16
16
17
17
package org .springframework .test .context .support ;
18
18
19
- import java .util .Arrays ;
20
- import java .util .List ;
21
-
22
19
import org .apache .commons .logging .Log ;
23
20
import org .apache .commons .logging .LogFactory ;
24
21
@@ -88,33 +85,36 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
88
85
protected abstract SmartContextLoader getAnnotationConfigLoader ();
89
86
90
87
91
- // SmartContextLoader
88
+ // ContextLoader
92
89
93
- private static void delegateProcessing (SmartContextLoader loader , ContextConfigurationAttributes configAttributes ) {
94
- if (logger .isDebugEnabled ()) {
95
- logger .debug (String .format ("Delegating to %s to process context configuration %s." ,
96
- name (loader ), configAttributes ));
97
- }
98
- loader .processContextConfiguration (configAttributes );
90
+ /**
91
+ * {@code AbstractDelegatingSmartContextLoader} does not support the
92
+ * {@link ContextLoader#processLocations(Class, String...)} method. Call
93
+ * {@link #processContextConfiguration(ContextConfigurationAttributes)} instead.
94
+ * @throws UnsupportedOperationException in this implementation
95
+ */
96
+ @ Override
97
+ public final String [] processLocations (Class <?> clazz , @ Nullable String ... locations ) {
98
+ throw new UnsupportedOperationException (
99
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
100
+ "Call processContextConfiguration(ContextConfigurationAttributes) instead." );
99
101
}
100
102
101
- private static ApplicationContext delegateLoading (SmartContextLoader loader , MergedContextConfiguration mergedConfig )
102
- throws Exception {
103
-
104
- if (logger .isDebugEnabled ()) {
105
- logger .debug (String .format ("Delegating to %s to load context from %s." , name (loader ), mergedConfig ));
106
- }
107
- return loader .loadContext (mergedConfig );
103
+ /**
104
+ * {@code AbstractDelegatingSmartContextLoader} does not support the
105
+ * {@link ContextLoader#loadContext(String...) } method. Call
106
+ * {@link #loadContext(MergedContextConfiguration)} instead.
107
+ * @throws UnsupportedOperationException in this implementation
108
+ */
109
+ @ Override
110
+ public final ApplicationContext loadContext (String ... locations ) throws Exception {
111
+ throw new UnsupportedOperationException (
112
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
113
+ "Call loadContext(MergedContextConfiguration) instead." );
108
114
}
109
115
110
- private boolean supports (SmartContextLoader loader , MergedContextConfiguration mergedConfig ) {
111
- if (loader == getAnnotationConfigLoader ()) {
112
- return (mergedConfig .hasClasses () && !mergedConfig .hasLocations ());
113
- }
114
- else {
115
- return (mergedConfig .hasLocations () && !mergedConfig .hasClasses ());
116
- }
117
- }
116
+
117
+ // SmartContextLoader
118
118
119
119
/**
120
120
* Delegates to candidate {@code SmartContextLoaders} to process the supplied
@@ -228,15 +228,14 @@ else if (configAttributes.hasClasses()) {
228
228
*/
229
229
@ Override
230
230
public ApplicationContext loadContext (MergedContextConfiguration mergedConfig ) throws Exception {
231
- Assert .notNull (mergedConfig , "mergedConfig must not be null" );
231
+ Assert .notNull (mergedConfig , "MergedContextConfiguration must not be null" );
232
232
233
233
Assert .state (!(mergedConfig .hasLocations () && mergedConfig .hasClasses ()), () -> String .format (
234
234
"Neither %s nor %s supports loading an ApplicationContext from %s: " +
235
235
"declare either 'locations' or 'classes' but not both." , name (getXmlLoader ()),
236
236
name (getAnnotationConfigLoader ()), mergedConfig ));
237
237
238
238
SmartContextLoader [] candidates = {getXmlLoader (), getAnnotationConfigLoader ()};
239
-
240
239
for (SmartContextLoader loader : candidates ) {
241
240
// Determine if each loader can load a context from the mergedConfig. If it
242
241
// can, let it; otherwise, keep iterating.
@@ -254,41 +253,39 @@ public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) t
254
253
255
254
// else...
256
255
throw new IllegalStateException (String .format (
257
- "Neither %s nor %s was able to load an ApplicationContext from %s." , name ( getXmlLoader ()),
258
- name (getAnnotationConfigLoader ()), mergedConfig ));
256
+ "Neither %s nor %s was able to load an ApplicationContext from %s." ,
257
+ name (getXmlLoader ()), name ( getAnnotationConfigLoader ()), mergedConfig ));
259
258
}
260
259
261
- private static String name (SmartContextLoader loader ) {
262
- return loader .getClass ().getSimpleName ();
260
+
261
+ private static void delegateProcessing (SmartContextLoader loader , ContextConfigurationAttributes configAttributes ) {
262
+ if (logger .isDebugEnabled ()) {
263
+ logger .debug (String .format ("Delegating to %s to process context configuration %s." ,
264
+ name (loader ), configAttributes ));
265
+ }
266
+ loader .processContextConfiguration (configAttributes );
263
267
}
264
268
269
+ private static ApplicationContext delegateLoading (SmartContextLoader loader , MergedContextConfiguration mergedConfig )
270
+ throws Exception {
265
271
266
- // ContextLoader
272
+ if (logger .isDebugEnabled ()) {
273
+ logger .debug (String .format ("Delegating to %s to load context from %s." , name (loader ), mergedConfig ));
274
+ }
275
+ return loader .loadContext (mergedConfig );
276
+ }
267
277
268
- /**
269
- * {@code AbstractDelegatingSmartContextLoader} does not support the
270
- * {@link ContextLoader#processLocations(Class, String...)} method. Call
271
- * {@link #processContextConfiguration(ContextConfigurationAttributes)} instead.
272
- * @throws UnsupportedOperationException in this implementation
273
- */
274
- @ Override
275
- public final String [] processLocations (Class <?> clazz , @ Nullable String ... locations ) {
276
- throw new UnsupportedOperationException (
277
- "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
278
- "Call processContextConfiguration(ContextConfigurationAttributes) instead." );
278
+ private boolean supports (SmartContextLoader loader , MergedContextConfiguration mergedConfig ) {
279
+ if (loader == getAnnotationConfigLoader ()) {
280
+ return (mergedConfig .hasClasses () && !mergedConfig .hasLocations ());
281
+ }
282
+ else {
283
+ return (mergedConfig .hasLocations () && !mergedConfig .hasClasses ());
284
+ }
279
285
}
280
286
281
- /**
282
- * {@code AbstractDelegatingSmartContextLoader} does not support the
283
- * {@link ContextLoader#loadContext(String...) } method. Call
284
- * {@link #loadContext(MergedContextConfiguration)} instead.
285
- * @throws UnsupportedOperationException in this implementation
286
- */
287
- @ Override
288
- public final ApplicationContext loadContext (String ... locations ) throws Exception {
289
- throw new UnsupportedOperationException (
290
- "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
291
- "Call loadContext(MergedContextConfiguration) instead." );
287
+ private static String name (SmartContextLoader loader ) {
288
+ return loader .getClass ().getSimpleName ();
292
289
}
293
290
294
291
}
0 commit comments