Prior to this commit, there was no declarative mechanism for a custom
TestExecutionListener to be registered as a default
TestExecutionListener.
This commit introduces support for discovering default
TestExecutionListener implementations via the SpringFactoriesLoader
mechanism. Specifically, the spring-test module declares all core
default TestExecutionListeners under the
org.springframework.test.context.TestExecutionListener key in its
META-INF/spring.factories properties file, and third-party frameworks
and developers can contribute to the list of default
TestExecutionListeners in the same manner.
- AbstractTestContextBootstrapper uses the SpringFactoriesLoader to
look up the class names of all registered default
TestExecutionListeners and sorts the instantiated listeners using
AnnotationAwareOrderComparator.
- DefaultTestContextBootstrapper and WebTestContextBootstrapper now
rely on the SpringFactoriesLoader mechanism for finding default
TestExecutionListeners instead of hard coding fully qualified class
names.
- To ensure that default TestExecutionListeners are registered in the
correct order, each can implement Ordered or declare @Order.
- AbstractTestExecutionListener and all default TestExecutionListeners
provided by Spring now implement Ordered with appropriate values.
- Introduced "copy constructors" in MergedContextConfiguration and
WebMergedContextConfiguration
- SpringFactoriesLoader now uses AnnotationAwareOrderComparator
instead of OrderComparator.
Issue: SPR-11466
@ -79,6 +79,7 @@ public class MergedContextConfiguration implements Serializable {
@@ -79,6 +79,7 @@ public class MergedContextConfiguration implements Serializable {
@ -185,6 +186,18 @@ public class MergedContextConfiguration implements Serializable {
@@ -185,6 +186,18 @@ public class MergedContextConfiguration implements Serializable {
@ -89,6 +89,14 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
@@ -89,6 +89,14 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen
@ -98,6 +99,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -98,6 +99,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -105,9 +107,10 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -105,9 +107,10 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
// Use defaults?
if(descriptor==null){
if(logger.isDebugEnabled()){
logger.debug("@TestExecutionListeners is not present for class ["+clazz.getName()
+"]: using defaults.");
logger.debug(String.format("@TestExecutionListeners is not present for class [%s]: using defaults.",
@ -142,6 +145,20 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -142,6 +145,20 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -194,6 +211,28 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -194,6 +211,28 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -302,9 +341,11 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -302,9 +341,11 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -383,15 +424,6 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -383,15 +424,6 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -403,34 +435,19 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@@ -403,34 +435,19 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
@ -75,4 +76,16 @@ public abstract class AbstractTestExecutionListener implements TestExecutionList
@@ -75,4 +76,16 @@ public abstract class AbstractTestExecutionListener implements TestExecutionList
@ -78,22 +37,4 @@ public class DefaultTestContextBootstrapper extends AbstractTestContextBootstrap
@@ -78,22 +37,4 @@ public class DefaultTestContextBootstrapper extends AbstractTestContextBootstrap
@ -49,11 +48,19 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
@@ -49,11 +48,19 @@ public class DependencyInjectionTestExecutionListener extends AbstractTestExecut
@ -48,20 +48,11 @@ public class DirtiesContextTestExecutionListener extends AbstractTestExecutionLi
@@ -48,20 +48,11 @@ public class DirtiesContextTestExecutionListener extends AbstractTestExecutionLi
@ -132,4 +123,21 @@ public class DirtiesContextTestExecutionListener extends AbstractTestExecutionLi
@@ -132,4 +123,21 @@ public class DirtiesContextTestExecutionListener extends AbstractTestExecutionLi
@ -144,6 +144,14 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@@ -144,6 +144,14 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
@ -87,6 +87,14 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@@ -87,6 +87,14 @@ public class ServletTestExecutionListener extends AbstractTestExecutionListener
@ -84,8 +84,7 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration {
@@ -84,8 +84,7 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration {
@ -122,6 +121,19 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration {
@@ -122,6 +121,19 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration {
@ -79,33 +54,21 @@ public class WebTestContextBootstrapper extends DefaultTestContextBootstrapper {
@@ -79,33 +54,21 @@ public class WebTestContextBootstrapper extends DefaultTestContextBootstrapper {
// test##_ prefix is required for @FixMethodOrder.
@ -50,6 +67,10 @@ public class TransactionalSqlScriptsTests extends AbstractTransactionalJUnit4Spr
@@ -50,6 +67,10 @@ public class TransactionalSqlScriptsTests extends AbstractTransactionalJUnit4Spr