Mockito doReturn: ambiguous reference to overloaded definition

As a temporary workaround, you can do the following:

trait MockitoHelper extends MockitoSugar {
  def doReturn(toBeReturned: Any): Stubber = {
    Mockito.doReturn(toBeReturned, Nil: _*)
  }
}

Then have your test mixin this MockitoHelper.


There is a ticket in the Scala backlog on it. see https://github.com/scala/bug/issues/4775


This is a bit of self promotion but I just published a library called mockito-scala that solves this issue and many more, is part of the mockito ecosystem so hopefully should become the default when working with Scala, you can find it here https://github.com/mockito/mockito-scala with the information to get the dependency and what problems does it actually solves.

Specifically for your problem, you could write this code and it would work out of the box

doReturn(Future.successful(())).when(f.adapterSpy).myFunction(userData, Some(offerId), Always)

I changed the way the future is expressed just because is the correct way to create a completed future of Unit


This can also be overcome by using doAnswer instead of doReturn

// no good
doReturn(true).when(foo).bar()
// works
doAnswer(_ => true).when(foo).bar()