Skip to content

Commit c52a0cc

Browse files
committed
Introduce TestContextManager(TestContextBootstrapper) constructor
Issue: SPR-12683
1 parent 9e6a5ae commit c52a0cc

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,35 +90,35 @@ public class TestContextManager {
9090

9191

9292
/**
93-
* Construct a new {@code TestContextManager} for the specified {@linkplain Class test class},
94-
* automatically {@linkplain #registerTestExecutionListeners registering} the necessary
95-
* {@link TestExecutionListener TestExecutionListeners}.
96-
* <p>Delegates to a {@link TestContextBootstrapper} for building the {@code TestContext}
97-
* and retrieving the {@code TestExecutionListeners}.
93+
* Construct a new {@code TestContextManager} for the supplied {@linkplain Class test class}.
94+
* <p>Delegates to {@link #TestContextManager(TestContextBootstrapper)} with
95+
* the {@link TestContextBootstrapper} configured for the test class. If the
96+
* {@link BootstrapWith @BootstrapWith} annotation is present on the test
97+
* class, either directly or as a meta-annotation, then its
98+
* {@link BootstrapWith#value value} will be used as the bootstrapper type;
99+
* otherwise, the {@link org.springframework.test.context.support.DefaultTestContextBootstrapper
100+
* DefaultTestContextBootstrapper} will be used.
98101
* @param testClass the test class to be managed
99-
* @see TestContextBootstrapper#buildTestContext
100-
* @see TestContextBootstrapper#getTestExecutionListeners
101-
* @see #registerTestExecutionListeners
102+
* @see #TestContextManager(TestContextBootstrapper)
102103
*/
103104
public TestContextManager(Class<?> testClass) {
104-
BootstrapContext bootstrapContext = createBootstrapContext(testClass);
105-
TestContextBootstrapper bootstrapper = BootstrapUtils.resolveTestContextBootstrapper(bootstrapContext);
106-
this.testContext = bootstrapper.buildTestContext();
107-
registerTestExecutionListeners(bootstrapper.getTestExecutionListeners());
105+
this(BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.createBootstrapContext(testClass)));
108106
}
109107

110108
/**
111-
* Create the {@code BootstrapContext} for the specified {@linkplain Class test class}.
112-
* <p>The default implementation creates a
113-
* {@link org.springframework.test.context.support.DefaultBootstrapContext DefaultBootstrapContext}
114-
* that uses a
115-
* {@link org.springframework.test.context.support.DefaultCacheAwareContextLoaderDelegate DefaultCacheAwareContextLoaderDelegate}.
116-
* <p>Can be overridden by subclasses as necessary.
117-
* @param testClass the test class for which the bootstrap context should be created
118-
* @return a new {@code BootstrapContext}; never {@code null}
109+
* Construct a new {@code TestContextManager} using the supplied {@link TestContextBootstrapper}
110+
* and {@linkplain #registerTestExecutionListeners register} the necessary
111+
* {@link TestExecutionListener TestExecutionListeners}.
112+
* <p>Delegates to the supplied {@code TestContextBootstrapper} for building
113+
* the {@code TestContext} and retrieving the {@code TestExecutionListeners}.
114+
* @param testContextBootstrapper the bootstrapper to use
115+
* @see TestContextBootstrapper#buildTestContext
116+
* @see TestContextBootstrapper#getTestExecutionListeners
117+
* @see #registerTestExecutionListeners
119118
*/
120-
protected BootstrapContext createBootstrapContext(Class<?> testClass) {
121-
return BootstrapUtils.createBootstrapContext(testClass);
119+
public TestContextManager(TestContextBootstrapper testContextBootstrapper) {
120+
this.testContext = testContextBootstrapper.buildTestContext();
121+
registerTestExecutionListeners(testContextBootstrapper.getTestExecutionListeners());
122122
}
123123

124124
/**

0 commit comments

Comments
 (0)