Skip to content

Commit a946643

Browse files
committed
Merge branch '5.3.x'
# Conflicts: # spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java
2 parents 7637a8d + 711820e commit a946643

File tree

3 files changed

+51
-38
lines changed

3 files changed

+51
-38
lines changed

spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,40 +73,6 @@ public DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache) {
7373
this.contextCache = contextCache;
7474
}
7575

76-
/**
77-
* Get the {@link ContextCache} used by this context loader delegate.
78-
*/
79-
protected ContextCache getContextCache() {
80-
return this.contextCache;
81-
}
82-
83-
/**
84-
* Load the {@code ApplicationContext} for the supplied merged context configuration.
85-
* <p>Supports both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
86-
* @throws Exception if an error occurs while loading the application context
87-
*/
88-
@SuppressWarnings("deprecation")
89-
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
90-
throws Exception {
91-
92-
ContextLoader contextLoader = mergedContextConfiguration.getContextLoader();
93-
Assert.notNull(contextLoader, "Cannot load an ApplicationContext with a NULL 'contextLoader'. " +
94-
"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");
95-
96-
ApplicationContext applicationContext;
97-
98-
if (contextLoader instanceof SmartContextLoader smartContextLoader) {
99-
applicationContext = smartContextLoader.loadContext(mergedContextConfiguration);
100-
}
101-
else {
102-
String[] locations = mergedContextConfiguration.getLocations();
103-
Assert.notNull(locations, "Cannot load an ApplicationContext with a NULL 'locations' array. " +
104-
"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");
105-
applicationContext = contextLoader.loadContext(locations);
106-
}
107-
108-
return applicationContext;
109-
}
11076

11177
@Override
11278
public boolean isContextLoaded(MergedContextConfiguration mergedContextConfiguration) {
@@ -152,4 +118,35 @@ public void closeContext(MergedContextConfiguration mergedContextConfiguration,
152118
}
153119
}
154120

121+
/**
122+
* Get the {@link ContextCache} used by this context loader delegate.
123+
*/
124+
protected ContextCache getContextCache() {
125+
return this.contextCache;
126+
}
127+
128+
/**
129+
* Load the {@code ApplicationContext} for the supplied merged context configuration.
130+
* <p>Supports both the {@link SmartContextLoader} and {@link ContextLoader} SPIs.
131+
* @throws Exception if an error occurs while loading the application context
132+
*/
133+
@SuppressWarnings("deprecation")
134+
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
135+
throws Exception {
136+
137+
ContextLoader contextLoader = mergedContextConfiguration.getContextLoader();
138+
Assert.notNull(contextLoader, "Cannot load an ApplicationContext with a NULL 'contextLoader'. " +
139+
"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");
140+
141+
if (contextLoader instanceof SmartContextLoader smartContextLoader) {
142+
return smartContextLoader.loadContext(mergedContextConfiguration);
143+
}
144+
else {
145+
String[] locations = mergedContextConfiguration.getLocations();
146+
Assert.notNull(locations, "Cannot load an ApplicationContext with a NULL 'locations' array. " +
147+
"Consider annotating your test class with @ContextConfiguration or @ContextHierarchy.");
148+
return contextLoader.loadContext(locations);
149+
}
150+
}
151+
155152
}

spring-test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,10 @@ public final ConfigurableApplicationContext loadContext(String... locations) thr
241241
* Factory method for creating the {@link GenericApplicationContext} used by
242242
* this {@code ContextLoader}.
243243
* <p>The default implementation creates a {@code GenericApplicationContext}
244-
* using the default constructor. This method may get overridden e.g. to use
245-
* a custom context subclass or to create a {@code GenericApplicationContext}
246-
* with a custom {@link DefaultListableBeanFactory} implementation.
244+
* using the default constructor. This method may be overridden &mdash; for
245+
* example, to use a custom context subclass or to create a
246+
* {@code GenericApplicationContext} with a custom
247+
* {@link DefaultListableBeanFactory} implementation.
247248
* @return a newly instantiated {@code GenericApplicationContext}
248249
* @since 5.2.9
249250
*/

spring-test/src/main/java/org/springframework/test/context/web/AbstractGenericWebContextLoader.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private final GenericWebApplicationContext loadContext(
157157

158158
validateMergedContextConfiguration(webMergedConfig);
159159

160-
GenericWebApplicationContext context = new GenericWebApplicationContext();
160+
GenericWebApplicationContext context = createContext();
161161

162162
ApplicationContext parent = mergedConfig.getParentApplicationContext();
163163
if (parent != null) {
@@ -192,6 +192,21 @@ protected void validateMergedContextConfiguration(WebMergedContextConfiguration
192192
// no-op
193193
}
194194

195+
/**
196+
* Factory method for creating the {@link GenericWebApplicationContext} used
197+
* by this {@code ContextLoader}.
198+
* <p>The default implementation creates a {@code GenericWebApplicationContext}
199+
* using the default constructor. This method may be overridden &mdash; for
200+
* example, to use a custom context subclass or to create a
201+
* {@code GenericWebApplicationContext} with a custom
202+
* {@link DefaultListableBeanFactory} implementation.
203+
* @return a newly instantiated {@code GenericWebApplicationContext}
204+
* @since 5.2.23
205+
*/
206+
protected GenericWebApplicationContext createContext() {
207+
return new GenericWebApplicationContext();
208+
}
209+
195210
/**
196211
* Configures web resources for the supplied web application context (WAC).
197212
* <h4>Implementation Details</h4>

0 commit comments

Comments
 (0)