这可能是 PowerMock/EasyMock 101 问题,我不知道为什么。我有一个带有方法的 C 类
public static boolean testInner(String s) {
return false;
}
public static boolean testOuter() {
String x = "someValue";
return testInner(x);
}
在我对 testOuter() 方法的测试中,我想确保使用适当的参数调用 testInner。为此,我正在做这样的事情: [@RunWith(PowerMockRunner.class) @PrepareForTest(EmailUtil.class) 在类级别声明]
EasyMock.expect(C.testInner("blabla")).andReturn(true);
PowerMock.replayAll();
boolean status = C.testOuter();
PowerMock.verifyAll();
assertTrue(status);
但我收到错误:
java.lang.AssertionError:
Unexpected method call testOuter():
testInner("blabla"): expected: 1, actual: 0
at org.easymock.internal.MockInvocationHandler.invoke(MockInvocationHandler.java:45)
at org.powermock.api.easymock.internal.invocationcontrol.EasyMockMethodInvocationControl.invoke(EasyMockMethodInvocationControl.java:95)
at org.powermock.core.MockGateway.doMethodCall(MockGateway.java:105)
at org.powermock.core.MockGateway.methodCall(MockGateway.java:60)
at C.testOuter(C.java)
我用 EasyMock.IsA(String.class) 替换了实际参数,但仍然没有运气。我很确定我在这里做的事情基本上很愚蠢。有什么帮助吗?