Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mockito.verify to ignore one of the parameters

Tags:

mockito

verify

I want to skip checking one of the parameters in a verify call. So for:

def allowMockitoVerify=Mockito.verify(msg,atLeastOnce()).handle(1st param,,3rd param)

I want to skip checking for the second parameter. How can I do that?

like image 663
user2854849 Avatar asked Oct 18 '13 08:10

user2854849


People also ask

What does verify method do in Mockito?

Mockito Verify methods are used to check that certain behavior happened. We can use Mockito verify methods at the end of the testing method code to make sure that specified methods are called.

Does Mockito verify use equals?

Mockito verifies argument values in natural java style: by using an equals() method.

Which method in Mockito verifies that no interaction has happened with a mock in Java?

Mockito verifyZeroInteractions() method It verifies that no interaction has occurred on the given mocks. It also detects the invocations that have occurred before the test method, for example, in setup(), @Before method or the constructor.


1 Answers

Unfortunately Mockito wont allow you to mix and match raw values and matchers (e.g. String and Matchers.any())

However you can use the eq() Matcher to match against a specific value, for example

Mockito.verify(msg, atLeastOnce())
  .handle(eq("someValue"), any(Thing.class), eq("anotherValue"));

Thanks to this post for a good example of this Mockito: InvalidUseOfMatchersException

like image 82
David Martin Avatar answered Oct 02 '22 14:10

David Martin