From 28270ba2bd2be3c3f66eeafbeca15d09ba63cc5f Mon Sep 17 00:00:00 2001 From: Emmanuel Bourg Date: Fri, 5 Oct 2018 14:13:31 +0200 Subject: New upstream version 4.3.19 --- .../AbstractDelegatingSmartContextLoader.java | 106 ++++++++++----------- 1 file changed, 52 insertions(+), 54 deletions(-) (limited to 'spring-test/src/main/java/org/springframework/test/context/support/AbstractDelegatingSmartContextLoader.java') 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 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(); } } -- cgit v1.2.3