I raised a fake issue on mockito-scala : https://github.com/mockito/mockito-scala/issues/191 But I am still stuck with my problem.
So basically, I have stubbed answers for one method. I am sure that the stubbed method is executed with the correct parameters (debug mode enter in it):
val mocked = mock[Service]
mocked.execute(*, *, *) answers {(f:Parameter, s:Parameter, t:Parameter) =>
s match {
case _:SecondParameter => // Debug mode enter here
Right("Second")
case o => Left(o)
}
})
Then i verify with a very broad verification : mocked.method(*, *, *) wasCalled atLeastOnce
but my test is failing:
Wanted but not invoked:
mocked.method(
<any>,
<any>,
<any>
);
-> at **hidden**
However, there were exactly 4 interactions with this mock:
mocked.init();
-> at **hidden**
mocked.method(
FirstParameter,
SecondParameter,
ThirdParameter
);
-> at **hidden**
mocked.method(
FirstParameter,
OtherParameter,
ThirdParameter
);
-> at **hidden**
mocked.method(
FirstParameter,
YetAnotherParameter,
ThirdParameter
);
-> at **hidden**
Edit 1: There is a class between the mock[Service]
and the test subject. Can it be the cause of this issue ?
class ServiceProxy(service: Service) {
def execute(p:Parameter) = Future {
val state = service.init()
service.execute(state, p, new ThirdParameter())
}
}
class Subject(proxy:ServiceProxy) {
def doSomething(s:String, n:Int) = {
val parameter = createParameter(s, n)
proxy.execute(parameter)
}
}
// In my test case
val mocked = mock[Service]
mocked.init() returns mock[State]
mocked.execute(*, *, *) answers // Same as above
val subject = new Subject(new ServiceProxy(mocked))
val response = subject.doSomething("A", 1)
Await.result(response, Duration.Inf)
mocked.method(*, *, *) wasCalled atLeastOnce