Why does thenCallRealMethod() lose 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 Command pattern - it encapsulates some concrete action, in this case, simplified - division operation. The result retrieval happens not directly, but by the means of contract method, say getResult(arg1, arg2) . So, I call

  mockedOperation.division(10d, 3d);

But (from debugging info in my concrete implementation of Operation ) I can see that division() gets not 10 and 3 but (0, 0) .

As far as I understand, that arguments are lost somewhere between the thenCallRealMethod() by getResult() and calling real division() afterwards.

What is the reason for that behavior and how should I implement partial mocks correctly in case I really need it?

UPD. Maybe I should try to say it another way, for example, simply how do you create mocks that callRealMethod in such a way that arguments are correctly delivered to the endpoint?


OK, the problem is solved now. Turns out I just encountered another undocumented feature/bug in Mockito (or just the feature I didn't find the docs for yet). The problem was that in my @Before I also mocked that very operation, and, as it appears, when one redefines mock, something black-magical happens and the result is as I've already described - arguments are somehow lost.

链接地址: http://www.djcxy.com/p/17710.html

上一篇: 确定github为什么说“因未提交的提交而关闭”

下一篇: 为什么thenCallRealMethod()在这里失去了参数?