我不太了解下面测试的行为。看着它,test_OK并且test_Not_OK严格等效-唯一的区别是test_OK具有“内联” callMethod。
但是,test_OK通过而test_Not_OK失败。这种行为有原因吗?
public class MethodCallTest {
@Test
public void test_Not_OK() {
new NonStrictExpectations() {
Whatever w;
{
callMethod();
}
private void callMethod() {
w.method();
result = 1;
}
};
assertEquals(new Whatever().method(), 1); //fails
}
@Test
public void test_OK() {
new NonStrictExpectations() {
Whatever w;
{
w.method();
result = 1;
}
};
assertEquals(new Whatever().method(), 1); //passes
}
public static class Whatever {
public int method() {
return 0;
}
}
}