When writing a groovy test case you almost want to be concise and expressive… next time you’ll see the test you must undestand it quickly.
Here’s a small tip to enhance test writing.
Having :
def car = new Car() def jack = new People() def tom = new Cat();
Instead of writing somethings like :
car.addPeople ( people ) car.addCat ( tom )
it’s really simpler to write:
car += jack car += tom
To achieve this it’s as easy as writing a plus method in you model object.
public Object plus(Object o) {
if(o instanceof People) {
this.addPeople((People)o);
}
if(o instanceof Cat) {
this.addCat((Cat)o);
}
return this;
}
Just remember this method must return this.