Description
Overview
We are starting to use Spring AOP and have some issues with existing tests using ReflectionTestUtils
.
In one test, a private method of spring-bean A
is invoked via ReflectionTestUtils.invokeMethod
. This method calls a method of an injected spring-bean B
.
With spring-aop
in use, this does not work anymore. CGlib will not provide a proxied version of the private method. Therefore the private method of the proxy is invoked, and the proxy does not have the DI-beans present and therefore we encounter a NullPointerException
.
Now, my original assumption was that ReflectionTestUtils
should handle this (as the setField
/getField
methods explicitly deal with Spring proxies).
My question is: Is my assumption wrong – and if so, how do we invoke private methods in test – or is this an omission in the ReflectionTestUtils
?
Form a user's perspective I would have hoped that ReflectionTestUtils
would at least handle the invocation of private methods (there should never be a reason to invoke private methods on a proxy, should there?).
I found issue #18622 which seems to be the point where AOP invocations in setField
/getField
were considered.