문제

In my application, I have code that looks like -

request.setParameter("a",false);//line1
request.setParameter("b",someObject);//line2
request.setParameter("c",someObject);//line3
request.setParameter("d",someObject);//line4

I have mocked the request object and now I want to verify if the line3 was invoked or not. I do not care about the other lines, in the test class I tried- Mockito.verify(request).setParameter("c",someObject) , however I get error -

Argument(s) are different! Wanted:
request.setParameter("c",com.test.MyObject@fec107);
-> at XXX

Actual invocation has different arguments:
request.setParameter("a", false);

For some reason, Mockito compares the first invocation and throws error

도움이 되었습니까?

해결책

Mockito will only do that if the invocation that you're verifying did NOT in fact happen. So if request.setParameter("c", someObject) had been called, your test would pass, regardless of the other calls. If a verify fails, Mockito tries to be helpful by identifying calls that were a "near miss" to the one that you tried to verify; but only if the verify fails.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top