Marten Deinum opened SPR-14050 and commented
When using Spring AOP and in a test case you use ReflectionTestUtils.setField, this fails when using (class-based) proxies. Specifically, the value is set in the proxy itself rather than in the underlying instance.
Currently one would first have to call AopTestUtils.getUltimateTargetObject and then pass that result to the ReflectionTestUtils.setField method.
Object actualTarget = AopTestUtils.getUltimateTargetObject(injectedProxy);
ReflectionTestUtils.setField(actualTarget, "field", "new-value");
 
Arguably calling ReflectionTestUtils.setField on a proxied class isn't the best practice, but it would be nice if the call to  AopTestUtils.getUltimateTargetObject could be embedded in the ReflectionTestUtils class.
Affects: 4.2.5
Referenced from: pull request #1006
0 votes, 5 watchers