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 b0b93195bb..e481092c4e 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 @@ -90,21 +90,36 @@ public class TestContextManager { /** - * Construct a new {@code TestContextManager} for the specified {@linkplain Class test class} - * and automatically {@linkplain #registerTestExecutionListeners register} the - * {@link TestExecutionListener TestExecutionListeners} configured for the test class - * via the {@link TestExecutionListeners @TestExecutionListeners} annotation. + * Construct a new {@code TestContextManager} for the specified {@linkplain Class test class}, + * automatically {@linkplain #registerTestExecutionListeners registering} the necessary + * {@link TestExecutionListener TestExecutionListeners}. + *
Delegates to a {@link TestContextBootstrapper} for building the {@code TestContext} + * and retrieving the {@code TestExecutionListeners}. * @param testClass the test class to be managed + * @see TestContextBootstrapper#buildTestContext + * @see TestContextBootstrapper#getTestExecutionListeners * @see #registerTestExecutionListeners */ public TestContextManager(Class> testClass) { - CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = new DefaultCacheAwareContextLoaderDelegate(); - BootstrapContext bootstrapContext = new DefaultBootstrapContext(testClass, cacheAwareContextLoaderDelegate); + BootstrapContext bootstrapContext = createBootstrapContext(testClass); TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(bootstrapContext); this.testContext = testContextBootstrapper.buildTestContext(); registerTestExecutionListeners(testContextBootstrapper.getTestExecutionListeners()); } + /** + * Create the {@code BootstrapContext} for the specified {@linkplain Class test class}. + *
The default implementation creates a {@link DefaultBootstrapContext} that + * uses the {@link DefaultCacheAwareContextLoaderDelegate}. + *
Can be overridden by subclasses as necessary. + * @param testClass the test class for which the bootstrap context should be created + * @return a new {@code BootstrapContext}; never {@code null} + */ + protected BootstrapContext createBootstrapContext(Class> testClass) { + CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = new DefaultCacheAwareContextLoaderDelegate(); + return new DefaultBootstrapContext(testClass, cacheAwareContextLoaderDelegate); + } + /** * Get the {@link TestContext} managed by this {@code TestContextManager}. */