Home > gcontracts > gcontracts Status Update

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 property firstName to your Person class is as simple as typing:

class Person {
    String firstName
    // ...    
}

Compared to its Java equivalent that is as simple as it can get.

public class Person {
    private String firstName;

    public void setFirstName(String anotherFirstName)  {
        firstName = anotherFirstName;
    }

    public String getFirstName()  {
        return firstName;
    }
}

Up to now, gcontracts injected class invariants only in explicitly declared setter methods, but users reported the need for class invariant injection on writeable POGO properties.

Today, i am glad to tell you that gcontracts class invariant injection mechanisms now works with POGO properties. Whenever a class declares an invariant, that invariant is injected in every dynamically generated setter method of that class.

E.g. a class invariant like,

@Invariant({ firstName != null })
class Person {
    String firstName
    // ...    
}

causes a java.lang.AssertionError whenever

def me = new Person("Andre")
me.firstName = null

is called.

Support for class invariant injection in POGO properties is currently available in github’s Master branch and will be part of gcontracts 1.0.1.

[0] Github – gcontracts
[1] Groovy Beans

Advertisements
Categories: gcontracts
  1. No comments yet.
  1. April 27, 2010 at 6:54 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: