相关疑难解决方法(0)

PowerMockito似乎无法匹配和重载方法

我似乎无法克服这个问题.我正在尝试模拟一个带有1个参数的重载方法

class ClassWithOverloadedMethod {
    private boolean isValid(ClassA a){
        return true;
    }

    private boolean isValid(ClassB B){
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

模拟设置

ClassWithOverloadedMethod uut = PowerMockito.spy(new ClassWithOverloadedMethod());
PowerMockito.doReturn(true).when(uut, "isValid", Matchers.isA(ClassB.class));
Run Code Online (Sandbox Code Playgroud)

但PowerMockito继续返回此错误

java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.powermock.reflect.internal.WhiteboxImpl.checkIfParameterTypesAreSame(WhiteboxImpl.java:2432)
at org.powermock.reflect.internal.WhiteboxImpl.getMethods(WhiteboxImpl.java:1934)
at org.powermock.reflect.internal.WhiteboxImpl.getBestMethodCandidate(WhiteboxImpl.java:1025)
at org.powermock.reflect.internal.WhiteboxImpl.findMethodOrThrowException(WhiteboxImpl.java:948)
at org.powermock.reflect.internal.WhiteboxImpl.doInvokeMethod(WhiteboxImpl.java:882)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:713)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:401)
at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.when(PowerMockitoStubberImpl.java:93)
Run Code Online (Sandbox Code Playgroud)

我正在使用PowerMockito 1.5和Mockito 1.9.5

overloading mockito powermock

3
推荐指数
1
解决办法
3766
查看次数

标签 统计

mockito ×1

overloading ×1

powermock ×1