Class BeanOverrideTestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
org.springframework.test.context.bean.override.BeanOverrideTestExecutionListener
- All Implemented Interfaces:
Ordered
,TestExecutionListener
TestExecutionListener
implementation that enables Bean Override
support in tests, injecting overridden beans in appropriate fields of the
test instance.- Since:
- 6.2
- Author:
- Simon Baslé
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
beforeTestMethod
(TestContext testContext) The default implementation is empty.int
getOrder()
Executes almost last (LOWEST_PRECEDENCE - 50
).protected void
injectFields
(TestContext testContext) Process the test instance and make sure that flagged fields for bean overriding are processed.void
prepareTestInstance
(TestContext testContext) The default implementation is empty.protected void
reinjectFieldsIfConfigured
(TestContext testContext) Process the test instance and make sure that flagged fields for bean overriding are processed.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()Executes almost last (LOWEST_PRECEDENCE - 50
).- Specified by:
getOrder
in interfaceOrdered
- Overrides:
getOrder
in classAbstractTestExecutionListener
- Returns:
- the order value
- See Also:
-
prepareTestInstance
Description copied from class:AbstractTestExecutionListener
The default implementation is empty. Can be overridden by subclasses as necessary.- 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
Description copied from class:AbstractTestExecutionListener
The default implementation is empty. Can be overridden by subclasses as necessary.- 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:
-
injectFields
Process the test instance and make sure that flagged fields for bean overriding are processed. Each field get is value updated with the overridden bean instance. -
reinjectFieldsIfConfigured
Process the test instance and make sure that flagged fields for bean overriding are processed. If a fresh instance is required, the field is nulled out and then re-injected with the overridden bean instance.This method does nothing if the
DependencyInjectionTestExecutionListener.REINJECT_DEPENDENCIES_ATTRIBUTE
attribute is not present in theTestContext
.- Throws:
Exception
-