Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocking a Future Or in a Scala Spec

I'm having trouble with Mockito to mock a response from a method that returns either an Object or an Exception. The mocked method's 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 Future:

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?

like image 578
maloney Avatar asked Oct 21 '25 16:10

maloney


1 Answers

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.

Eg.

doReturn(Future.successful(Seq("hello"))).when(client).findR‌​esult("1234")

like image 75
rethab Avatar answered Oct 23 '25 06:10

rethab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!