Package org.springframework.test.util

# Class AopTestUtils

java.lang.Object
org.springframework.test.util.AopTestUtils

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`.

Since:
  4.2
Author:
  Sam Brannen, Juergen Hoeller
See Also:
  - `AopUtils`
  - `AopProxyUtils`
  - `ReflectionTestUtils`

## Constructor Summary

Constructors
Constructor
Description
`AopTestUtils()`

## Method Summary

Modifier and Type
Method
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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### AopTestUtils

public AopTestUtils()

## Method Details

### getTargetObject

public static <T> T getTargetObject(Object candidate)
Get the target object of the supplied `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.

Type Parameters:
  `T` - the type of the target object
Parameters:
  `candidate` - the instance to check (potentially a Spring AOP proxy; never `null`)
Returns:
  the target object or the `candidate` (never `null`)
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 supplied `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`.

Type Parameters:
  `T` - the type of the target object
Parameters:
  `candidate` - the instance to check (potentially a Spring AOP proxy; never `null`)
Returns:
  the target object or the `candidate` (never `null`)
Throws:
  `IllegalStateException` - if an error occurs while unwrapping a proxy
See Also:
  - `Advised.getTargetSource()`
  - `TargetSource.isStatic()`
  - `AopProxyUtils.ultimateTargetClass(java.lang.Object)`