I don't really understand the behaviour of the tests below. Looking at it, test_OK
and test_Not_OK
are strictly equivalent - the only difference is that test_OK
has "inlined" callMethod
.
However, test_OK
passes whereas test_Not_OK
fails. Is there a reason for that behaviour?
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;
}
}
}