Package org.springframework.test.util
Class AopTestUtils
- java.lang.Object
- org.springframework.test.util.AopTestUtils
public abstract class AopTestUtils extends Object
AopTestUtilsis a collection of AOP-related utility methods for use in unit and integration testing scenarios.For Spring's core AOP utilities, see
AopUtilsandAopProxyUtils.- Since:
- 4.2
- Author:
- Sam Brannen
- See Also:
AopUtils,AopProxyUtils,ReflectionTestUtils
Constructor Summary
Constructors Constructor Description AopTestUtils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TgetTargetObject(Object candidate)Get the target object of the suppliedcandidateobject.static <T> TgetUltimateTargetObject(Object candidate)Get the ultimate target object of the suppliedcandidateobject, unwrapping not only a top-level proxy but also any number of nested proxies.
Constructor Detail
AopTestUtils
public AopTestUtils()
Method Detail
getTargetObject
public static <T> T getTargetObject(Object candidate)
Get the target object of the suppliedcandidateobject.If the supplied
candidateis a Spring proxy, the target of the proxy will be returned; otherwise, thecandidatewill be returned as is.- Parameters:
candidate- the instance to check (potentially a Spring AOP proxy; nevernull)- Returns:
- the target object or the
candidate(nevernull) - Throws:
IllegalStateException- if an error occurs while unwrapping a proxy- See Also:
Advised.getTargetSource(),getUltimateTargetObject(java.lang.Object)
getUltimateTargetObject
public static <T> T getUltimateTargetObject(Object candidate)
Get the ultimate target object of the suppliedcandidateobject, unwrapping not only a top-level proxy but also any number of nested proxies.If the supplied
candidateis a Spring proxy, the ultimate target of all nested proxies will be returned; otherwise, thecandidatewill be returned as is.- Parameters:
candidate- the instance to check (potentially a Spring AOP proxy; nevernull)- Returns:
- the target object or the
candidate(nevernull) - Throws:
IllegalStateException- if an error occurs while unwrapping a proxy- See Also:
Advised.getTargetSource(),AopProxyUtils.ultimateTargetClass(java.lang.Object)