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?
If you want to include design by contracts in your java development, Cofoja is definitely a better choice:
http://code.google.com/p/cofoja/
Edit: Setting up Cofoja in Eclipse:
http://fsteeg.com/2011/02/07/setting-up-contracts-for-java-in-eclipse/