Why thenCallRealMethod () loses the arguments here?

I have the following code:

when(mockedOperation.getResult(anyDouble(), anyDouble())).thenCallRealMethod(); when(mockedOperation.division(anyDouble(), not(eq(0d)))).thenCallRealMethod(); 

Where Operation is something like a Command pattern - it encapsulates some specific action, in this case a simplified one - division. The search result does not occur directly, but using the contract method, for example, getResult(arg1, arg2) . So I call

  mockedOperation.division(10d, 3d); 

But (from the debugging information in my specific implementation of Operation ), I see that division() gets not 10 and 3 , but (0, 0) .

As far as I understand, these arguments are lost somewhere between thenCallRealMethod() and getResult() and after that they call real division() .

What is the reason for this behavior and how should I correctly execute partial layouts, if I really need it?

UPD. Maybe I should try to say it differently, for example, just how do you create mocks that callRealMethod so that the arguments are correctly delivered to the endpoint?

+7
java mockito mocking
source share
1 answer

OK, the problem is resolved now. Turns out I just ran into yet another undocumented function / bug in Mockito (or just that feature on which I haven't found any documents yet). The problem was that in my @Before I also mocked this very operation and, as it turned out, when someone redefines the layout, something black and magic happens, and the result, as I already described, is some kind of argument way lost.

+3
source share

All Articles