PowerMockito: got InvalidUseOfMatchersException when use matchers mocking static method

前端 未结 4 911
遥遥无期
遥遥无期 2021-01-18 10:33

When I\'m testing this static method

public class SomeClass {
    public static long someMethod(Map map, String string, Long l, Log log) {
        ...
    }
         


        
4条回答
  •  独厮守ぢ
    2021-01-18 11:10

    Better late than never, the line below:

    Mockito.when(SomeClass.someMethod(anyMap(), anyString(), anyLong(),
        isA(Log.class))).thenReturn(1L);
    

    should be:

    PowerMockito.when(SomeClass.someMethod(anyMap(), anyString(), anyLong(),
        isA(Log.class))).thenReturn(1L);
    

    So, instead of invoking Mockito.when, one should invoke PowerMockito.when

提交回复
热议问题