Class BeanOverrideTestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener
- All Implemented Interfaces:
Ordered, TestExecutionListener
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
FieldsFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforeTestMethod(TestContext testContext) Re-inject each@BeanOverridefield in the test instance of the supplied test context with a corresponding bean override instance.intgetOrder()Returns 1950, which ensures that theBeanOverrideTestExecutionListeneris ordered after theDirtiesContextBeforeModesTestExecutionListenerand before theDependencyInjectionTestExecutionListener.voidprepareTestInstance(TestContext testContext) Inject each@BeanOverridefield in the test instance of the supplied test context with a corresponding bean override instance.Methods inherited from class AbstractTestExecutionListener
afterTestClass, afterTestExecution, afterTestMethod, beforeTestClass, beforeTestExecution
-
Field Details
-
ORDER
-
-
Constructor Details
-
BeanOverrideTestExecutionListener
public BeanOverrideTestExecutionListener()
-
-
Method Details
-
getOrder
public int getOrder()Returns 1950, which ensures that theBeanOverrideTestExecutionListeneris ordered after theDirtiesContextBeforeModesTestExecutionListenerand before theDependencyInjectionTestExecutionListener.- Specified by:
getOrderin interfaceOrdered- Overrides:
getOrderin classAbstractTestExecutionListener- Returns:
- the order value
- See Also:
-
prepareTestInstance
Inject each@BeanOverridefield in the test instance of the supplied test context with a corresponding bean override instance.- Specified by:
prepareTestInstancein interfaceTestExecutionListener- Overrides:
prepareTestInstancein classAbstractTestExecutionListener- Parameters:
testContext- the test context for the test; nevernull- Throws:
Exception- allows any exception to propagate- See Also:
-
beforeTestMethod
Re-inject each@BeanOverridefield in the test instance of the supplied test context with a corresponding bean override instance.This method does nothing if the
REINJECT_DEPENDENCIES_ATTRIBUTEattribute is not present in theTestContextwith a value ofBoolean.TRUE.- Specified by:
beforeTestMethodin interfaceTestExecutionListener- Overrides:
beforeTestMethodin classAbstractTestExecutionListener- Parameters:
testContext- the test context in which the test method will be executed; nevernull- Throws:
Exception- allows any exception to propagate- See Also:
-