public abstract class AopTestUtils extends Object
AopTestUtils
is a collection of AOP-related utility methods for
use in unit and integration testing scenarios.
For Spring's core AOP utilities, see
AopUtils
and
AopProxyUtils
.
AopUtils
,
AopProxyUtils
,
ReflectionTestUtils
Constructor and Description |
---|
AopTestUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
getTargetObject(Object candidate)
Get the target object of the supplied
candidate object. |
static <T> T |
getUltimateTargetObject(Object candidate)
Get the ultimate target object of the supplied
candidate
object, unwrapping not only a top-level proxy but also any number of
nested proxies. |
public static <T> T getTargetObject(Object candidate)
candidate
object.
If the supplied candidate
is a Spring
proxy, the target of the proxy will
be returned; otherwise, the candidate
will be returned
as is.
T
- the type of the target objectcandidate
- the instance to check (potentially a Spring AOP proxy;
never null
)candidate
(never null
)IllegalStateException
- if an error occurs while unwrapping a proxyAdvised.getTargetSource()
,
getUltimateTargetObject(java.lang.Object)
public static <T> T getUltimateTargetObject(Object candidate)
candidate
object, unwrapping not only a top-level proxy but also any number of
nested proxies.
If the supplied candidate
is a Spring
proxy, the ultimate target of all
nested proxies will be returned; otherwise, the candidate
will be returned as is.
NOTE: If the top-level proxy or a nested proxy is not backed by a
static
TargetSource
, invocation of
this utility method may result in undesired behavior such as infinite
recursion leading to a StackOverflowError
.
T
- the type of the target objectcandidate
- the instance to check (potentially a Spring AOP proxy;
never null
)candidate
(never null
)IllegalStateException
- if an error occurs while unwrapping a proxyAdvised.getTargetSource()
,
TargetSource.isStatic()
,
AopProxyUtils.ultimateTargetClass(java.lang.Object)