Mockito for int primitive

后端 未结 2 1476
梦如初夏
梦如初夏 2021-02-06 23:18

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

2条回答
  •  暖寄归人
    2021-02-07 00:01

    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.

提交回复
热议问题