I have a class that looks like this (from Spring Roo DataOnDemand), which returns a new transient (non-persistent) object for use in unit testing. This is what the code looks like after we enter from Spring Roo ITD.
public class MyObjectOnDemand { public MyObjectOnDemand getNewTransientObject(int index) { MyObjectOnDemand obj = new MyObjectOnDemand(); return obj; } }
I need to make additional calls to refer to the returned object in order to set additional fields that the Spring Roo automatically generated method does not care about. Therefore, without changing the above code (or clicking it with Roo ITD), I want to make another call:
obj.setName("test_name_" + index);
To do this, I announced a new aspect that has the correct pointcut and which will report 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, pointcut is spelled correctly and advises the correct method. But this does not seem to happen because the integration tests that are stored in the object still do not work, because the name attribute is required but not set. And according to Manning AspectJ in action (section 4.3.2), after consultation, it is assumed that he will be able to change the return values. But maybe I need to do around () advice instead?
source share