maloney maloney - 1 year ago 96
Scala Question

Mocking a Future Or in a Scala Spec

I'm having trouble trying to use Mockito to mock a response from a method that returns wither an

or an
. The mocked method signature looks like this:

def findResult(request: String): Future[Seq[String] Or MyException] =

and in my Specs I'm trying to just return a succesful

when(client.findResult("1234")) thenReturn Future.successful[Seq[String] Or MyException](Seq("Hello"))

This of course does not compile but what is the correct syntax?

Answer Source

Well you need to decide what you want to return. Depending on the test, you may want to return the left or the right side of the Or.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download