mardi 7 janvier 2020

Stubbing multi parameters method with mockito-scala

I am trying to stub a method with three parameters to return different responses regarding one of those parameters:

val mocked = mock[MyService]
mocked.someInitialization returns mock[State]
mocked.complexMethod(*, *, *) answers { (_:State, discriminant:Discriminant, _:Delegate[MyService]) => 
  discriminant match {
    case _:FirstKind => Right(Option.empty[String])
    case SecondKind(value:String) => Right(Some(value))
    case _ => ???
  }
}

However, my test fail with the above message:

SmartNull returned by this unstubbed method call on a mock:
myService.complexMethod(
    Mock for State, hashCode: 1730688778,
    FirstKind("UnusedValue"),
    my.system.FixturesAndMock$FakeDelegate@2b5f8e61
); (of class scala.util.Either$MockitoMock$854506859)

(I don't understand the sentence "of class scala.util.Either$MockitoMock$854506859")

Note that:

  • stubbing with mocked.complexMethod(*, *, *) returns Left(Nil) have the same issue.
  • using any[State], any[Discriminant], any[Delegate[MyService]] instead of *, *, * does not change anything.

I am using org.mockito.scalatest.IdiomaticMockito on Scala 2.12.8 on GraalVM. What am I doing wrong; how can I stub a method to return computed answers ?

Thanks

Aucun commentaire:

Enregistrer un commentaire