Browse Source

Introduce TestContextManager(TestContextBootstrapper) constructor

Issue: SPR-12683
pull/783/head
Sam Brannen 10 years ago
parent
commit
c52a0ccdfd
  1. 44
      spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

44
spring-test/src/main/java/org/springframework/test/context/TestContextManager.java

@ -90,35 +90,35 @@ public class TestContextManager { @@ -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}.
* <p>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}.
* <p>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}.
* <p>The default implementation creates a
* {@link org.springframework.test.context.support.DefaultBootstrapContext DefaultBootstrapContext}
* that uses a
* {@link org.springframework.test.context.support.DefaultCacheAwareContextLoaderDelegate DefaultCacheAwareContextLoaderDelegate}.
* <p>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}.
* <p>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());
}
/**

Loading…
Cancel
Save