9

I don't know how can I use Mockito.verify in this case. How can I pass false to Mockito.verify? I try 2 different ways but it does not work.

public Sample someMethod(Sample s, boolean a){....}
@Test
public void test() {
...
verify(mock).someMethod(sampleCaptor.capture(), false));
verify(mock).someMethod(sampleCaptor.capture(), org.mockito.Matchers.eq(false)));
...
}
Thanh Duy Ngo
  • 1,521
  • 6
  • 17
  • 25

1 Answers1

15

You have it right the second way:

verify(mock).someMethod(sampleCaptor.capture(), Matchers.eq(false));

When using Matchers (including ArgumentCaptor.capture), you have to use a Matcher for every value, because Matchers work via side-effects.

If the above doesn't work, you may be misusing matchers earlier in the method. It is sometimes helpful to explicitly call Mockito.validateMockitoUsage() immediately before your call to verify, to ensure that there's nothing wrong with Mockito's internal state. (Additional information about how it "does not work", including a minimal reproducible example, may be helpful in solving your specific case.)

Community
  • 1
  • 1
Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
  • Hi. Thank you for your help. I found the error that I made. I create a mock for someMethod but call true boolean, that's why it could not run. – Thanh Duy Ngo Nov 05 '15 at 06:44