I have a class that looks like follows (from Spring Roo DataOnDemand) which returns a new transient (not persisted) object for use in unit testing. This is what the code looks like after we do a push-in from Spring Roo's ITD.
public class MyObjectOnDemand {
public MyObjectOnDemand getNewTransientObject(int index) {
MyObjectOnDemand obj = new MyObjectOnDemand();
return obj;
}
}
What I need to do is make additional calls on the returned object reference to set additional fields that Spring Roo's auto-generated method is not taking care of. So without modifying the above code (or pushing it in from Roo's ITD), I want to make one additional call:
obj.setName("test_name_" + index);
To do this, I have declared a new aspect which has the proper pointcut and which is going to advise the specific method.
public aspect MyObjectDataOnDemandAdvise {
pointcut pointcutGetNewTransientMyObject() :
execution(public MyObject MyObjectDataOnDemand.getNewTransientObject(int));
after() returning(MyObject obj) :
pointcutGetNewTransientMyObject() {
obj.setName("test_name_" + index);
}
}
Now, according to Eclipse, the pointcut is written properly and is advising the proper method. But it doesn't seem to be happening because the integration tests which persist out the object are still failing because the name attribute is required, but is not being set. And according to Manning's AspectJ in Action (section 4.3.2) the after advice is supposed to be able to modify return values. But maybe I need to do an around() advice instead?