I thought I understood CodePro's contracts, but they seem to have no effect. For example:
public class ContractTest {
private int number;
/**
* @pre inputNumber > 0
*
* Alternatively:
* @post number > 0
*/
public void setNumber(int inputNumber) {
number = inputNumber;
}
public int getNumber() {
return number;
}
public static void main(String args[]) {
ConditionsTest conditionsTest = new ConditionsTest();
conditionsTest.setNumber(-5);
System.out.println("Number: " + conditionsTest.getNumber());
}
}
Running the main(String[]) method causes:
number: -5
to be printed. There were no compile warning (expected), and no exceptions thrown. Also, the junit test methods generated by CodePro were not affected by the contracts.
So how do you use CodePro's contracts?