If I am using a Wrapper class type variable as argument Mockito test case is getting pass but, how to write Mockito test case for int primitive type variable which is an argumen
You may have some trouble with any
or argThat
for primitive-type arguments to when
and verify
. Those Object-centric methods do their work with side-effects correctly, but they tend to return null
for a dummy return value, which doesn't work for Java unwrapping primitives via auto-boxing.
Luckily, the org.mockito.ArgumentMatchers
class has a full complement of primitive-centric methods (of which I've listed the int
methods here):
static int anyInt()
static int eq(int value)
static int intThat(org.hamcrest.ArgumentMatcher matcher)
See all of them at the documentation for the ArgumentMatchers class.