JMockit: 1.10
Here is a code snippet
import java.math.BigDecimal;
import mockit.NonStrictExpectations;
import mockit.internal.UnexpectedInvocation;
import org.junit.Test;
public class Test1 {
@Test
public void test1() {
new NonStrictExpectations(BigDecimal.class) {{
new BigDecimal(0).intValue();
result = 1;
maxTimes = 2;
}};
BigDecimal bigDecimal = BigDecimal.valueOf(0); // Invocation OK
bigDecimal.intValue();
bigDecimal.intValue();
BigDecimal.valueOf(0); // Invocation still OK
try {
bigDecimal.intValue();
} catch (UnexpectedInvocation e) {
}
BigDecimal.valueOf(0); // Unexpected invocation!!
}
}
As you can see, til UnexpectedInvocation was thrown the BigDecimal class was partially mocked. But after UnexpectedInvocation was thrown BigDecimal turns into non-partially and also strict mocked class.