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
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 org.springframework.core.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 org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestExecution, afterTestMethod, beforeTestClass, beforeTestExecution
-
Field Details
-
ORDER
public static final int ORDERTheordervalue for this listener: 1950.- Since:
- 6.2.3
- See Also:
-
-
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 interfaceorg.springframework.core.Ordered- Overrides:
getOrderin classAbstractTestExecutionListener
-
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
-
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:
-