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
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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()
Returns1950
, which ensures that theBeanOverrideTestExecutionListener
is ordered after theDirtiesContextBeforeModesTestExecutionListener
and just before theDependencyInjectionTestExecutionListener
.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
-
Constructor Details
-
BeanOverrideTestExecutionListener
public BeanOverrideTestExecutionListener()
-
-
Method Details
-
getOrder
public int getOrder()Returns1950
, which ensures that theBeanOverrideTestExecutionListener
is ordered after theDirtiesContextBeforeModesTestExecutionListener
and just before theDependencyInjectionTestExecutionListener
.- Specified by:
getOrder
in interfaceOrdered
- Overrides:
getOrder
in classAbstractTestExecutionListener
- Returns:
- the order value
- See Also:
-
prepareTestInstance
Inject each@BeanOverride
field in the test instance of the supplied test context with a corresponding bean override instance.- Specified by:
prepareTestInstance
in interfaceTestExecutionListener
- Overrides:
prepareTestInstance
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context for the test; nevernull
- Throws:
Exception
- allows any exception to propagate
-
beforeTestMethod
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 theTestContext
with a value ofBoolean.TRUE
.- Specified by:
beforeTestMethod
in interfaceTestExecutionListener
- Overrides:
beforeTestMethod
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context in which the test method will be executed; nevernull
- Throws:
Exception
- allows any exception to propagate- See Also:
-