From d5ce30f36051a2c7adbddb3c1bade8211de055f7 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 10 Apr 2014 17:54:14 +0200 Subject: [PATCH] Deprecate custom/default CtxLdr class name in TCF Once the new bootstrap strategy for the TestContext framework (TCF) is introduced in Spring Framework 4.1, a TestContextBootstrapper will assume full responsibility for determining what ContextLoader to use as the default. Consequently, the previous support for supplying the class name for a custom, default ContextLoader will no longer be applicable. This commit therefore officially deprecates support for custom, default ContextLoader class names via the following mechanisms: - The TestContextManager(Class, String) constructor - The getDefaultContextLoaderClassName(Class) method in SpringJUnit4ClassRunner Issue: SPR-11682 --- .../test/context/TestContextManager.java | 25 +++++---- .../junit4/SpringJUnit4ClassRunner.java | 55 ++++++++++--------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java index d68ac414e8b..0956b684f1d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextManager.java @@ -53,18 +53,18 @@ import static org.springframework.test.context.MetaAnnotationUtils.*; * * * @author Sam Brannen @@ -109,12 +109,15 @@ public class TestContextManager { * Constructs a new {@code TestContextManager} for the specified {@linkplain Class * test class} and automatically {@link #registerTestExecutionListeners registers} the * {@link TestExecutionListener TestExecutionListeners} configured for the test class - * via the {@link TestExecutionListeners @TestExecutionListeners} annotation. + * via the {@link TestExecutionListeners @TestExecutionListeners} annotation. * @param testClass the test class to be managed * @param defaultContextLoaderClassName the name of the default {@code ContextLoader} * class to use (may be {@code null}) * @see #registerTestExecutionListeners(TestExecutionListener...) + * @deprecated Spring Framework 4.1 will introduce a bootstrap strategy for + * the TestContext framework at which point this constructor will be removed. */ + @Deprecated public TestContextManager(Class testClass, String defaultContextLoaderClassName) { this.testContext = new DefaultTestContext(testClass, contextCache, defaultContextLoaderClassName); registerTestExecutionListeners(retrieveTestExecutionListeners(testClass)); @@ -164,10 +167,10 @@ public class TestContextManager { /** * Retrieve an array of newly instantiated {@link TestExecutionListener TestExecutionListeners} - * for the specified {@link Class class}. If {@link TestExecutionListeners @TestExecutionListeners} + * for the specified {@link Class class}. If {@link TestExecutionListeners @TestExecutionListeners} * is not present on the supplied class, the default listeners will be returned. *

Note that the {@link TestExecutionListeners#inheritListeners() inheritListeners} flag of - * {@link TestExecutionListeners @TestExecutionListeners} will be taken into consideration. + * {@link TestExecutionListeners @TestExecutionListeners} will be taken into consideration. * Specifically, if the {@code inheritListeners} flag is set to {@code true}, listeners * defined in the annotated class will be appended to the listeners defined in superclasses. * @param clazz the test class for which the listeners should be retrieved @@ -268,7 +271,7 @@ public class TestContextManager { * Hook for pre-processing a test class before execution of any * tests within the class. Should be called prior to any framework-specific * before class methods (e.g., methods annotated with JUnit's - * {@link org.junit.BeforeClass @BeforeClass}). + * {@link org.junit.BeforeClass @BeforeClass}). *

An attempt will be made to give each registered * {@link TestExecutionListener} a chance to pre-process the test class * execution. If a listener throws an exception, however, the remaining @@ -334,7 +337,7 @@ public class TestContextManager { * {@link Method test method}, for example for setting up test fixtures, * starting a transaction, etc. Should be called prior to any * framework-specific before methods (e.g., methods annotated with - * JUnit's {@link org.junit.Before @Before}). + * JUnit's {@link org.junit.Before @Before}). *

The managed {@link TestContext} will be updated with the supplied * {@code testInstance} and {@code testMethod}. *

An attempt will be made to give each registered @@ -372,7 +375,7 @@ public class TestContextManager { * {@link Method test method}, for example for tearing down test fixtures, * ending a transaction, etc. Should be called after any framework-specific * after methods (e.g., methods annotated with JUnit's - * {@link org.junit.After @After}). + * {@link org.junit.After @After}). *

The managed {@link TestContext} will be updated with the supplied * {@code testInstance}, {@code testMethod}, and * {@code exception}. @@ -424,7 +427,7 @@ public class TestContextManager { * Hook for post-processing a test class after execution of all * tests within the class. Should be called after any framework-specific * after class methods (e.g., methods annotated with JUnit's - * {@link org.junit.AfterClass @AfterClass}). + * {@link org.junit.AfterClass @AfterClass}). *

Each registered {@link TestExecutionListener} will be given a chance to * post-process the test class. If a listener throws an exception, the * remaining registered listeners will still be called, but the first diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java index aa0fd1d0bc7..a1dcd56c985 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/SpringJUnit4ClassRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,16 +65,14 @@ import org.springframework.util.ReflectionUtils; * TestExecutionListeners}) *

* *

* NOTE: As of Spring 3.0, {@code SpringJUnit4ClassRunner} requires @@ -131,20 +129,23 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { * Get the name of the default {@code ContextLoader} class to use for * the supplied test class. The named class will be used if the test class * does not explicitly declare a {@code ContextLoader} class via the - * {@code @ContextConfiguration} annotation. + * {@code @ContextConfiguration} annotation. *

The default implementation returns {@code null}, thus implying use * of the standard default {@code ContextLoader} class name. - * Can be overridden by subclasses. + *

Can be overridden by subclasses. * @param clazz the test class * @return {@code null} + * @deprecated Spring Framework 4.1 will introduce a bootstrap strategy for + * the TestContext framework at which point this method will be removed. */ + @Deprecated protected String getDefaultContextLoaderClassName(Class clazz) { return null; } /** * Returns a description suitable for an ignored test class if the test is - * disabled via {@code @IfProfileValue} at the class-level, and + * disabled via {@code @IfProfileValue} at the class-level, and * otherwise delegates to the parent implementation. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Class) */ @@ -158,7 +159,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { /** * Check whether the test is enabled in the first place. This prevents - * classes with a non-matching {@code @IfProfileValue} annotation + * classes with a non-matching {@code @IfProfileValue} annotation * from running altogether, even skipping the execution of * {@code prepareTestInstance()} {@code TestExecutionListener} * methods. @@ -260,13 +261,13 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { * {@link #withPotentialRepeat(FrameworkMethod, Object, Statement) with * potential repeats} of the entire execution chain. *

Furthermore, support for timeouts has been moved down the execution chain - * in order to include execution of {@link org.junit.Before @Before} - * and {@link org.junit.After @After} methods within the timed + * in order to include execution of {@link org.junit.Before @Before} + * and {@link org.junit.After @After} methods within the timed * execution. Note that this differs from the default JUnit behavior of - * executing {@code @Before} and {@code @After} methods + * executing {@code @Before} and {@code @After} methods * in the main thread while executing the actual test method in a separate - * thread. Thus, the end effect is that {@code @Before} and - * {@code @After} methods will be executed in the same thread as + * thread. Thus, the end effect is that {@code @Before} and + * {@code @After} methods will be executed in the same thread as * the test method. As a consequence, JUnit-specified timeouts will work * fine in combination with Spring transactions. Note that JUnit-specific * timeouts still differ from Spring-specific timeouts in that the former @@ -324,9 +325,9 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { } /** - * Returns {@code true} if {@link Ignore @Ignore} is present for + * Returns {@code true} if {@link Ignore @Ignore} is present for * the supplied {@link FrameworkMethod test method} or if the test method is - * disabled via {@code @IfProfileValue}. + * disabled via {@code @IfProfileValue}. * @see ProfileValueUtils#isTestEnabledInThisEnvironment(Method, Class) */ protected boolean isTestMethodIgnored(FrameworkMethod frameworkMethod) { @@ -362,8 +363,8 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { } /** - * Supports both Spring's {@link Timed @Timed} and JUnit's - * {@link Test#timeout() @Test(timeout=...)} annotations, but not both + * Supports both Spring's {@link Timed @Timed} and JUnit's + * {@link Test#timeout() @Test(timeout=...)} annotations, but not both * simultaneously. Returns either a {@link SpringFailOnTimeout}, a * {@link FailOnTimeout}, or the unmodified, supplied {@link Statement} as * appropriate. @@ -397,8 +398,8 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { } /** - * Retrieves the configured JUnit {@code timeout} from the {@link Test - * @Test} annotation on the supplied {@link FrameworkMethod test method}. + * Retrieves the configured JUnit {@code timeout} from the {@link Test @Test} + * annotation on the supplied {@link FrameworkMethod test method}. * @return the timeout, or {@code 0} if none was specified. */ protected long getJUnitTimeout(FrameworkMethod frameworkMethod) { @@ -408,7 +409,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { /** * Retrieves the configured Spring-specific {@code timeout} from the - * {@link Timed @Timed} annotation on the supplied + * {@link Timed @Timed} annotation on the supplied * {@link FrameworkMethod test method}. * @return the timeout, or {@code 0} if none was specified. */ @@ -453,7 +454,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner { } /** - * Supports Spring's {@link Repeat @Repeat} annotation by returning a + * Supports Spring's {@link Repeat @Repeat} annotation by returning a * {@link SpringRepeat} statement initialized with the configured repeat * count or {@code 1} if no repeat count is configured. * @see SpringRepeat