Skip to content

Commit c9d597f

Browse files
committed
Introduce createBootstrapContext() extension in TestContextManager
Issue: SPR-12683
1 parent 0b054f9 commit c9d597f

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

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

9191

9292
/**
93-
* Construct a new {@code TestContextManager} for the specified {@linkplain Class test class}
94-
* and automatically {@linkplain #registerTestExecutionListeners register} the
95-
* {@link TestExecutionListener TestExecutionListeners} configured for the test class
96-
* via the {@link TestExecutionListeners @TestExecutionListeners} annotation.
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}.
9798
* @param testClass the test class to be managed
99+
* @see TestContextBootstrapper#buildTestContext
100+
* @see TestContextBootstrapper#getTestExecutionListeners
98101
* @see #registerTestExecutionListeners
99102
*/
100103
public TestContextManager(Class<?> testClass) {
101-
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = new DefaultCacheAwareContextLoaderDelegate();
102-
BootstrapContext bootstrapContext = new DefaultBootstrapContext(testClass, cacheAwareContextLoaderDelegate);
104+
BootstrapContext bootstrapContext = createBootstrapContext(testClass);
103105
TestContextBootstrapper testContextBootstrapper = BootstrapUtils.resolveTestContextBootstrapper(bootstrapContext);
104106
this.testContext = testContextBootstrapper.buildTestContext();
105107
registerTestExecutionListeners(testContextBootstrapper.getTestExecutionListeners());
106108
}
107109

110+
/**
111+
* Create the {@code BootstrapContext} for the specified {@linkplain Class test class}.
112+
* <p>The default implementation creates a {@link DefaultBootstrapContext} that
113+
* uses the {@link DefaultCacheAwareContextLoaderDelegate}.
114+
* <p>Can be overridden by subclasses as necessary.
115+
* @param testClass the test class for which the bootstrap context should be created
116+
* @return a new {@code BootstrapContext}; never {@code null}
117+
*/
118+
protected BootstrapContext createBootstrapContext(Class<?> testClass) {
119+
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate = new DefaultCacheAwareContextLoaderDelegate();
120+
return new DefaultBootstrapContext(testClass, cacheAwareContextLoaderDelegate);
121+
}
122+
108123
/**
109124
* Get the {@link TestContext} managed by this {@code TestContextManager}.
110125
*/

0 commit comments

Comments
 (0)