Mockito when().thenReturn calls the method unnecessarily

后端 未结 5 2320
挽巷
挽巷 2021-02-19 02:23

I\'m working a bit on an inherited code. I\'ve written a test that is supposed to catch NullPointerException (for it is trying to call a method from null object)



        
5条回答
  •  别那么骄傲
    2021-02-19 03:02

    You can use PowerMock. First create mock of the class on which you are calling static methods -

    mockStatic(BasketHelper.class);
    

    Then define your stubs -

    when(BasketHelper.getAction(request)).thenReturn(0);
    when(BasketHelper.getActionProduct(site, request)).thenReturn(product);
    

提交回复
热议问题