Written on
gcontracts Status Update
I am currently working on the gcontracts 1.0.1 release [0]. Apart from bug fixes, that version contains an important feature you might have been tumbled over: class invariant checking on Groovy bean properties. Groovy beans support a very simple syntax to declare properties [1]. E.g. adding a propertyfirstName
to your Person
class is as simple as typing:
class Person {
String firstName
// ...
}
public class Person {
private String firstName;
public void setFirstName(String anotherFirstName) {
firstName = anotherFirstName;
}
public String getFirstName() {
return firstName;
}
}
@Invariant({ firstName != null })
class Person {
String firstName
// ...
}
java.lang.AssertionError
whenever
def me = new Person("Andre")
me.firstName = null
[1] Groovy Beans