Class DependencyInjectiontestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstracttestExecutionListener
org.springframework.test.context.support.DependencyInjectiontestExecutionListener
- All Implemented Interfaces:
Ordered, testExecutionListener
testExecutionListener which provides support for dependency
injection and initialization of test instances.- Since:
- 2.5
- Author:
- Sam Brannen, Juergen Hoeller
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intTheordervalue for this listener: 2000.static final StringAttribute name for atestContextattribute which indicates whether the dependencies of a test instance should be reinjected inbeforetestMethod().Fields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbeforetestMethod(testContext testContext) If theREINJECT_DEPENDENCIES_ATTRIBUTEin the suppliedtest contexthas a value ofBoolean.TRUE, this method will have the same effect aspreparetestInstance(); otherwise, this method will have no effect.final intgetOrder()Returns 2000, which ensures that theDependencyInjectiontestExecutionListeneris ordered after theDirtiesContextBeforeModestestExecutionListenerand theBeanOverridetestExecutionListenerand before theMicrometerObservationRegistrytestExecutionListenerand theDirtiesContexttestExecutionListener.protected voidinjectDependencies(testContext testContext) Performs dependency injection and bean initialization for the suppliedtestContextas described inpreparetestInstance().voidpreparetestInstance(testContext testContext) Performs dependency injection on thetest instanceof the suppliedtest contextbyautowiringandinitializingthe test instance via its ownapplication context(without checking dependencies).Methods inherited from class AbstracttestExecutionListener
aftertestClass, aftertestExecution, aftertestMethod, beforetestClass, beforetestExecution
-
Field Details
-
ORDER
-
REINJECT_DEPENDENCIES_ATTRIBUTE
Attribute name for atestContextattribute which indicates whether the dependencies of a test instance should be reinjected inbeforetestMethod(). Note that dependencies will be injected inpreparetestInstance()in any case.Clients of a
testContext(for example, othertestExecutionListeners) may therefore choose to set this attribute to signal that dependencies should be reinjected between execution of individual test methods.Permissible values include
Boolean.TRUEandBoolean.FALSE.
-
-
Constructor Details
-
DependencyInjectiontestExecutionListener
public DependencyInjectiontestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns 2000, which ensures that theDependencyInjectiontestExecutionListeneris ordered after theDirtiesContextBeforeModestestExecutionListenerand theBeanOverridetestExecutionListenerand before theMicrometerObservationRegistrytestExecutionListenerand theDirtiesContexttestExecutionListener.- Specified by:
getOrderin interfaceOrdered- Overrides:
getOrderin classAbstracttestExecutionListener- Returns:
- the order value
- See Also:
-
preparetestInstance
Performs dependency injection on thetest instanceof the suppliedtest contextbyautowiringandinitializingthe test instance via its ownapplication context(without checking dependencies).The
REINJECT_DEPENDENCIES_ATTRIBUTEwill be subsequently removed from the test context, regardless of its value.- 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
If theREINJECT_DEPENDENCIES_ATTRIBUTEin the suppliedtest contexthas a value ofBoolean.TRUE, this method will have the same effect aspreparetestInstance(); otherwise, this method will have no effect.- 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:
-
injectDependencies
Performs dependency injection and bean initialization for the suppliedtestContextas described inpreparetestInstance().The
REINJECT_DEPENDENCIES_ATTRIBUTEwill be subsequently removed from the test context, regardless of its value.- Parameters:
testContext- the test context for which dependency injection should be performed (nevernull)- Throws:
Exception- allows any exception to propagate- See Also:
-