How can I mock a method call with Mockito with an integer argument value greater then X?
I would like to write something like this:
doReturn("FooBar").when(persons).getPersons(Mockito.gt(10));
Mockito uses the matchers of Hamcrest. All of Mockitos argument matchers use these matchers to match the provided argument in a handy and type-safe way.
Mockito provides also the method argThat(Matcher)
to use any matcher implementation of Hamcrest or custom Matcher
implementation. There are also specialised versions as intThat(Matcher)
for all primitved types.
So, knowing that, I rewrote the mocking of the method call:
doReturn("FooBar")
.when(persons)
.getPersons(Mockito.intThat(Matchers.greaterThan(10));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With