PowerMockito: got InvalidUseOfMatchersException when use matchers mocking static method

前端 未结 4 881
遥遥无期
遥遥无期 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:19

    Try replacing the isA() to another any() call like this

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

    [EDIT]

    Check your stacktrace when you get the exception. Are you seeing any NoClassDefFoundError reported? I noticed when I hadn't included the javassist.jar in my project I got a similar error to you.

    I use PowerMockito and these are the jars I added to a brand new project to run the code that @Tom posted

    • powermock-mockito-1.4.10-full.jar
    • mockito-all-1.8.5.jar
    • javassist-3.15.0-GA.jar
    • junit-4.8.2.jar
    • common-logging-1.1.1.jar

    Always a good idea to check that you're using compatible JAR versions, and also check if there are any other conflicting JARs in your projects classpath.

提交回复
热议问题