From c52a0ccdfdc238e972e720f99e9ff86b6c0e8181 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 19 Apr 2015 20:09:03 +0200 Subject: [PATCH] Introduce TestContextManager(TestContextBootstrapper) constructor Issue: SPR-12683 --- .../test/context/TestContextManager.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 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 f217174721..3fd7767890 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,35 +90,35 @@ public class TestContextManager { /** - * 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}. + * Construct a new {@code TestContextManager} for the supplied {@linkplain Class test class}. + *

Delegates to {@link #TestContextManager(TestContextBootstrapper)} with + * the {@link TestContextBootstrapper} configured for the test class. If the + * {@link BootstrapWith @BootstrapWith} annotation is present on the test + * class, either directly or as a meta-annotation, then its + * {@link BootstrapWith#value value} will be used as the bootstrapper type; + * otherwise, the {@link org.springframework.test.context.support.DefaultTestContextBootstrapper + * DefaultTestContextBootstrapper} will be used. * @param testClass the test class to be managed - * @see TestContextBootstrapper#buildTestContext - * @see TestContextBootstrapper#getTestExecutionListeners - * @see #registerTestExecutionListeners + * @see #TestContextManager(TestContextBootstrapper) */ public TestContextManager(Class testClass) { - BootstrapContext bootstrapContext = createBootstrapContext(testClass); - TestContextBootstrapper bootstrapper = BootstrapUtils.resolveTestContextBootstrapper(bootstrapContext); - this.testContext = bootstrapper.buildTestContext(); - registerTestExecutionListeners(bootstrapper.getTestExecutionListeners()); + this(BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.createBootstrapContext(testClass))); } /** - * Create the {@code BootstrapContext} for the specified {@linkplain Class test class}. - *

The default implementation creates a - * {@link org.springframework.test.context.support.DefaultBootstrapContext DefaultBootstrapContext} - * that uses a - * {@link org.springframework.test.context.support.DefaultCacheAwareContextLoaderDelegate 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} + * Construct a new {@code TestContextManager} using the supplied {@link TestContextBootstrapper} + * and {@linkplain #registerTestExecutionListeners register} the necessary + * {@link TestExecutionListener TestExecutionListeners}. + *

Delegates to the supplied {@code TestContextBootstrapper} for building + * the {@code TestContext} and retrieving the {@code TestExecutionListeners}. + * @param testContextBootstrapper the bootstrapper to use + * @see TestContextBootstrapper#buildTestContext + * @see TestContextBootstrapper#getTestExecutionListeners + * @see #registerTestExecutionListeners */ - protected BootstrapContext createBootstrapContext(Class testClass) { - return BootstrapUtils.createBootstrapContext(testClass); + public TestContextManager(TestContextBootstrapper testContextBootstrapper) { + this.testContext = testContextBootstrapper.buildTestContext(); + registerTestExecutionListeners(testContextBootstrapper.getTestExecutionListeners()); } /**