Package org.springframework.test.context.bean.override

# Class BeanOverrideTestExecutionListener

java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener

All Implemented Interfaces:
  `org.springframework.core.Ordered`, `TestExecutionListener`

public class BeanOverrideTestExecutionListener extends AbstractTestExecutionListener
`TestExecutionListener` that enables `@BeanOverride` support in tests, by injecting overridden beans in appropriate fields of the test instance.

Since:
  6.2
Author:
  Simon Baslé, Sam Brannen, Phillip Webb, Andy Wilkinson, Moritz Halbritter

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ORDER`
The `order` value for this listener: 1950.

### Fields inherited from interface org.springframework.core.Ordered

`HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE`

## Constructor Summary

Constructors
Constructor
Description
`BeanOverrideTestExecutionListener()`

## Method Summary

Modifier and Type
Method
Description
`void`
`beforeTestMethod(TestContext testContext)`
Re-inject each `@BeanOverride` field in the test instance of the supplied test context with a corresponding bean override instance.
`int`
`getOrder()`
Returns 1950, which ensures that the `BeanOverrideTestExecutionListener` is ordered after the `DirtiesContextBeforeModesTestExecutionListener` and before the `DependencyInjectionTestExecutionListener`.
`void`
`prepareTestInstance(TestContext testContext)`
Inject each `@BeanOverride` field in the test instance of the supplied test context with a corresponding bean override instance.

### Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener

`afterTestClass, afterTestExecution, afterTestMethod, beforeTestClass, beforeTestExecution`

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

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

## Field Details

### ORDER

public static final int ORDER
The `order` value for this listener: 1950.

Since:
  6.2.3
See Also:
  - Constant Field Values

## Constructor Details

### BeanOverrideTestExecutionListener

public BeanOverrideTestExecutionListener()

## Method Details

### getOrder

public int getOrder()
Returns 1950, which ensures that the `BeanOverrideTestExecutionListener` is ordered after the `DirtiesContextBeforeModesTestExecutionListener` and before the `DependencyInjectionTestExecutionListener`.

Specified by:
  `getOrder` in interface `org.springframework.core.Ordered`
Overrides:
  `getOrder` in class `AbstractTestExecutionListener`

### prepareTestInstance

public void prepareTestInstance(TestContext testContext) throws Exception
Inject each `@BeanOverride` field in the test instance of the supplied test context with a corresponding bean override instance.

Specified by:
  `prepareTestInstance` in interface `TestExecutionListener`
Overrides:
  `prepareTestInstance` in class `AbstractTestExecutionListener`
Parameters:
  `testContext` - the test context for the test; never `null`
Throws:
  `Exception` - allows any exception to propagate

### beforeTestMethod

public void beforeTestMethod(TestContext testContext) throws Exception
Re-inject each `@BeanOverride` field in the test instance of the supplied test context with a corresponding bean override instance.

This method does nothing if the `REINJECT_DEPENDENCIES_ATTRIBUTE` attribute is not present in the `TestContext` with a value of `Boolean.TRUE`.

Specified by:
  `beforeTestMethod` in interface `TestExecutionListener`
Overrides:
  `beforeTestMethod` in class `AbstractTestExecutionListener`
Parameters:
  `testContext` - the test context in which the test method will be executed; never `null`
Throws:
  `Exception` - allows any exception to propagate
See Also:
  - `TestExecutionListener.afterTestMethod(org.springframework.test.context.TestContext)`
  - `TestExecutionListener.beforeTestExecution(org.springframework.test.context.TestContext)`
  - `TestExecutionListener.afterTestExecution(org.springframework.test.context.TestContext)`