In the following example MyManager uses interface MyInterface, but the implementor of MyManager has not honoured the contract @Pre("!=null"). (Fix for this could be e.g. using Google Guava's Strings.nullToEmpty in the callDo)
MyInterface.java :
public interface MyInterface {
@Post("result == 'success' || result == 'failure'")
String doIt(@Pre("!=null") String text);
}
MyManager.java :
public class MyManager {
private final MyInterface myInterface;
public MyManager(MyInterface myInterface) {
this.myInterface = myInterface;
}
public void callDo(String text) {
myInterface.doIt(text);
}
}
MyManagerTest.java :
public class MyManagerTest extends EasyMockSupportWithDbC {
@Test
public void test() {
MyInterface myInterface = createNiceMock(MyInterface.class);
MyManager myManager = new MyManager(myInterface);
replayAll();
myManager.callDo(null); // this will throw PreconditionException
verifyAll();
}
}
Also the implementor of MyInterface has been lazy, and has not honoured the postcondition @Post("result == 'success' || result == 'failure'").