class A{ public void aa(B b){} public void bb(){} } For mocking method bb() I used doNothing().when(A).bb();.
What should I use for function aa() Since it has arguments.
1 Answer
As a general rule, you shouldn't need doNothing, since mocks by default do "nothing" when their methods are called. You would only need to write doNothing if you are working with a spy instead of a mock.
In Mockito 1.x, you can write
doNothing().when(yourSpyGoesHere).aa(any(B.class)); which effectively disables any call to aa.
Unfortunately, the meaning of any was changed in Mockito 2, and this construction is no longer available. As far as I know, the Mockito team didn't provide any equivalent to the "old" meaning of any.
The best that I know of is to combine this with an extra stubbing to deal with the special case of the argument being null.
doNothing().when(yourSpyGoesHere).aa(any(B.class)); doNothing().when(yourSpyGoesHere).aa(null); 1