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 StringAttribute name for aTestContextattribute which indicates whether or not the dependencies of a test instance should be reinjected inbeforeTestMethod().Fields inherited from interface org.springframework.core.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()Returns2000.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 org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestExecution, afterTestMethod, beforeTestClass, beforeTestExecution
-
Field Details
-
REINJECT_DEPENDENCIES_ATTRIBUTE
Attribute name for aTestContextattribute which indicates whether or not the dependencies of a test instance should be reinjected inbeforeTestMethod(). Note that dependencies will be injected inprepareTestInstance()in any case.Clients of a
TestContext(e.g., 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()Returns2000.- 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
-
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:
-