In the sample code, is the difference between test methods matchSpecific and matchSpecific2 as design or a bug?
import mockit.*;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class MockMatchTest {
@Test
public void matchAll(@Mocked ContrivedInteger anyInstance) {
new Expectations() {{
anyInstance.intValue();
result = 1;
}};
assertEquals(1, new ContrivedInteger().intValue());
assertEquals(1, new ContrivedInteger(10).intValue());
}
@Test
public void matchSpecific(@Mocked ContrivedInteger anyInstance) {
new Expectations() {{
anyInstance.intValue();
result = 1;
ContrivedInteger specificInstance = new ContrivedInteger(anyInt);
specificInstance.intValue();
result = 2;
}};
// specific constructor matching
assertEquals(2, new ContrivedInteger(10).intValue());
// why expected: 0
assertEquals(0, new ContrivedInteger().intValue());
}
@Test
public void matchSpecific2(@Mocked ContrivedInteger anyInstance) {
new Expectations() {{
ContrivedInteger specificInstance = new ContrivedInteger(anyInt);
specificInstance.intValue();
result = 2;
anyInstance.intValue();
result = 1;
}};
// specific constructor matching
assertEquals(2, new ContrivedInteger(100).intValue());
// why expected: 1
assertEquals(1, new ContrivedInteger().intValue());
}
static class ContrivedInteger {
Integer value = null;
public ContrivedInteger() {this(-1);}
public ContrivedInteger(int value) {this.value = Integer.valueOf(value);}
public int intValue() {return value.intValue();}
}
}
The text was updated successfully, but these errors were encountered:
JMockit: 1.30
JUnit: 4.12
JDK: 1.8.0_111
In the sample code, is the difference between test methods matchSpecific and matchSpecific2 as design or a bug?
The text was updated successfully, but these errors were encountered: