8

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?

forsvarir
  • 10,749
  • 6
  • 46
  • 77
user2854849
  • 81
  • 1
  • 1
  • 3

3 Answers3

6

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

Community
  • 1
  • 1
David Martin
  • 666
  • 8
  • 12
5

You can try Mockito.any(), which basically means we are not interested in this parameter.

Community
  • 1
  • 1
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
0

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

tam.teixeira
  • 805
  • 7
  • 10