Package io.mats3.spring.test
Class SpringInjectRulesAndExtensions.SpringInjectRulesAndExtensionsTestExecutionListener
java.lang.Object
org.springframework.test.context.support.AbstractTestExecutionListener
io.mats3.spring.test.SpringInjectRulesAndExtensions.SpringInjectRulesAndExtensionsTestExecutionListener
- All Implemented Interfaces:
org.springframework.core.Ordered,org.springframework.test.context.TestExecutionListener
- Enclosing class:
- SpringInjectRulesAndExtensions
public static class SpringInjectRulesAndExtensions.SpringInjectRulesAndExtensionsTestExecutionListener
extends org.springframework.test.context.support.AbstractTestExecutionListener
This
TestExecutionListener finds all fields in the test class instance which is annotated with JUnit
Rule or JUnit 5 Jupiter RegisterExtension, and runs
beanFactory.autowireBean(fieldValue) on them.-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindFields(Class<?> clazz, String annotationClassName) Find all fields in class with given annotation.voidprepareTestInstance(org.springframework.test.context.TestContext testContext) Performs dependency injection onRuleand@RegisterExtensionfields in test-class as supplied by testContext.Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestExecution, afterTestMethod, beforeTestClass, beforeTestExecution, beforeTestMethod, getOrder
-
Constructor Details
-
SpringInjectRulesAndExtensionsTestExecutionListener
public SpringInjectRulesAndExtensionsTestExecutionListener()
-
-
Method Details
-
prepareTestInstance
public void prepareTestInstance(org.springframework.test.context.TestContext testContext) Performs dependency injection onRuleand@RegisterExtensionfields in test-class as supplied by testContext.- Specified by:
prepareTestInstancein interfaceorg.springframework.test.context.TestExecutionListener- Overrides:
prepareTestInstancein classorg.springframework.test.context.support.AbstractTestExecutionListener
-
findFields
Find all fields in class with given annotation. Amended from StackOverflow, inspired by Apache Commons Lang. https://stackoverflow.com/a/29766135
-