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?
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?
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
You can try Mockito.any(), which basically means we are not interested in this parameter.
I'm using Mockito 3.9.0
and because you cannot mix matchers with expected values, i.e, you can't verify that the first argument is a specific string like test-profile
and the second is anything, so you need to convert all to matchers, so you can't do something like:
verify(userAuthorizationService).authorizeRequest("test-profile", any());
Instead, you need to convert values into matchers, like:
verify(userAuthorizationService).authorizeRequest(matches("test-profile"), any());
Note the matches
and any
are static imports from org.mockito.ArgumentMatchers