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.void
prepareTestInstance
(org.springframework.test.context.TestContext testContext) Performs dependency injection onRule
and@RegisterExtension
fields 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 onRule
and@RegisterExtension
fields in test-class as supplied by testContext.- Specified by:
prepareTestInstance
in interfaceorg.springframework.test.context.TestExecutionListener
- Overrides:
prepareTestInstance
in 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
-