summaryrefslogtreecommitdiff
path: root/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
diff options
context:
space:
mode:
authorEmmanuel Bourg <ebourg@apache.org>2018-10-05 14:13:31 +0200
committerEmmanuel Bourg <ebourg@apache.org>2018-10-05 14:13:31 +0200
commit28270ba2bd2be3c3f66eeafbeca15d09ba63cc5f (patch)
treef34feaee40de5360852db87b08e7e5940d7f837c /spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
parentef9a891c4db2efcc1a454b14d96f82ce30000214 (diff)
New upstream version 4.3.19
Diffstat (limited to 'spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java')
-rw-r--r--spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java106
1 files changed, 52 insertions, 54 deletions
diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
index 95beb555..cdbd92b8 100644
--- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
+++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java
@@ -16,9 +16,6 @@
package org.springframework.test.context.support;
-import java.util.Arrays;
-import java.util.List;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -87,33 +84,36 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
protected abstract SmartContextLoader getAnnotationConfigLoader();
- // SmartContextLoader
+ // ContextLoader
- private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) {
- if (logger.isDebugEnabled()) {
- logger.debug(String.format("Delegating to %s to process context configuration %s.",
- name(loader), configAttributes));
- }
- loader.processContextConfiguration(configAttributes);
+ /**
+ * {@code AbstractDelegatingSmartContextLoader} does not support the
+ * {@link ContextLoader#processLocations(Class, String...)} method. Call
+ * {@link #processContextConfiguration(ContextConfigurationAttributes)} instead.
+ * @throws UnsupportedOperationException in this implementation
+ */
+ @Override
+ public final String[] processLocations(Class<?> clazz, String... locations) {
+ throw new UnsupportedOperationException(
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
+ "Call processContextConfiguration(ContextConfigurationAttributes) instead.");
}
- private static ApplicationContext delegateLoading(SmartContextLoader loader, MergedContextConfiguration mergedConfig)
- throws Exception {
-
- if (logger.isDebugEnabled()) {
- logger.debug(String.format("Delegating to %s to load context from %s.", name(loader), mergedConfig));
- }
- return loader.loadContext(mergedConfig);
+ /**
+ * {@code AbstractDelegatingSmartContextLoader} does not support the
+ * {@link ContextLoader#loadContext(String...) } method. Call
+ * {@link #loadContext(MergedContextConfiguration)} instead.
+ * @throws UnsupportedOperationException in this implementation
+ */
+ @Override
+ public final ApplicationContext loadContext(String... locations) throws Exception {
+ throw new UnsupportedOperationException(
+ "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
+ "Call loadContext(MergedContextConfiguration) instead.");
}
- private boolean supports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) {
- if (loader == getAnnotationConfigLoader()) {
- return (mergedConfig.hasClasses() && !mergedConfig.hasLocations());
- }
- else {
- return (mergedConfig.hasLocations() && !mergedConfig.hasClasses());
- }
- }
+
+ // SmartContextLoader
/**
* Delegates to candidate {@code SmartContextLoaders} to process the supplied
@@ -232,8 +232,7 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
*/
@Override
public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {
- Assert.notNull(mergedConfig, "mergedConfig must not be null");
- List<SmartContextLoader> candidates = Arrays.asList(getXmlLoader(), getAnnotationConfigLoader());
+ Assert.notNull(mergedConfig, "MergedContextConfiguration must not be null");
if (mergedConfig.hasLocations() && mergedConfig.hasClasses()) {
throw new IllegalStateException(String.format(
@@ -242,6 +241,7 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
name(getAnnotationConfigLoader()), mergedConfig));
}
+ SmartContextLoader[] candidates = {getXmlLoader(), getAnnotationConfigLoader()};
for (SmartContextLoader loader : candidates) {
// Determine if each loader can load a context from the mergedConfig. If it
// can, let it; otherwise, keep iterating.
@@ -259,41 +259,39 @@ public abstract class AbstractDelegatingSmartContextLoader implements SmartConte
// else...
throw new IllegalStateException(String.format(
- "Neither %s nor %s was able to load an ApplicationContext from %s.", name(getXmlLoader()),
- name(getAnnotationConfigLoader()), mergedConfig));
+ "Neither %s nor %s was able to load an ApplicationContext from %s.",
+ name(getXmlLoader()), name(getAnnotationConfigLoader()), mergedConfig));
}
- private static String name(SmartContextLoader loader) {
- return loader.getClass().getSimpleName();
+
+ private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Delegating to %s to process context configuration %s.",
+ name(loader), configAttributes));
+ }
+ loader.processContextConfiguration(configAttributes);
}
+ private static ApplicationContext delegateLoading(SmartContextLoader loader, MergedContextConfiguration mergedConfig)
+ throws Exception {
- // ContextLoader
+ if (logger.isDebugEnabled()) {
+ logger.debug(String.format("Delegating to %s to load context from %s.", name(loader), mergedConfig));
+ }
+ return loader.loadContext(mergedConfig);
+ }
- /**
- * {@code AbstractDelegatingSmartContextLoader} does not support the
- * {@link ContextLoader#processLocations(Class, String...)} method. Call
- * {@link #processContextConfiguration(ContextConfigurationAttributes)} instead.
- * @throws UnsupportedOperationException in this implementation
- */
- @Override
- public final String[] processLocations(Class<?> clazz, String... locations) {
- throw new UnsupportedOperationException(
- "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
- "Call processContextConfiguration(ContextConfigurationAttributes) instead.");
+ private boolean supports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) {
+ if (loader == getAnnotationConfigLoader()) {
+ return (mergedConfig.hasClasses() && !mergedConfig.hasLocations());
+ }
+ else {
+ return (mergedConfig.hasLocations() && !mergedConfig.hasClasses());
+ }
}
- /**
- * {@code AbstractDelegatingSmartContextLoader} does not support the
- * {@link ContextLoader#loadContext(String...) } method. Call
- * {@link #loadContext(MergedContextConfiguration)} instead.
- * @throws UnsupportedOperationException
- */
- @Override
- public final ApplicationContext loadContext(String... locations) throws Exception {
- throw new UnsupportedOperationException(
- "DelegatingSmartContextLoaders do not support the ContextLoader SPI. " +
- "Call loadContext(MergedContextConfiguration) instead.");
+ private static String name(SmartContextLoader loader) {
+ return loader.getClass().getSimpleName();
}
}