diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java b/org.springframework.test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java index b09c44cb42f..436fba4955d 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/ContextConfigurationAttributes.java @@ -34,14 +34,14 @@ public class ContextConfigurationAttributes { private final Class> declaringClass; - private String[] locations; - - private Class>[] classes; - private final boolean inheritLocations; private final Class extends ContextLoader> contextLoaderClass; + private String[] locations; + + private Class>[] classes; + /** * Resolves resource locations from the {@link ContextConfiguration#locations() locations} @@ -97,6 +97,20 @@ public class ContextConfigurationAttributes { return this.declaringClass; } + /** + * TODO Document isInheritLocations(). + */ + public boolean isInheritLocations() { + return this.inheritLocations; + } + + /** + * TODO Document getContextLoaderClass(). + */ + public Class extends ContextLoader> getContextLoaderClass() { + return this.contextLoaderClass; + } + /** * TODO Document getLocations(). */ @@ -125,20 +139,6 @@ public class ContextConfigurationAttributes { this.classes = classes; } - /** - * TODO Document isInheritLocations(). - */ - public boolean isInheritLocations() { - return this.inheritLocations; - } - - /** - * TODO Document getContextLoaderClass(). - */ - public Class extends ContextLoader> getContextLoaderClass() { - return this.contextLoaderClass; - } - /** * TODO Document overridden toString(). */ diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java index ddf77066abd..c3e3856d7d5 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/ContextLoaderUtils.java @@ -310,7 +310,7 @@ abstract class ContextLoaderUtils { if (contextLoader instanceof SmartContextLoader) { SmartContextLoader smartContextLoader = (SmartContextLoader) contextLoader; // TODO Decide on mutability of locations and classes properties - smartContextLoader.processContextConfigurationAttributes(configAttributes); + smartContextLoader.processContextConfiguration(configAttributes); locationsList.addAll(Arrays.asList(configAttributes.getLocations())); classesList.addAll(Arrays.asList(configAttributes.getClasses())); } diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/SmartContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/SmartContextLoader.java index abb847f72a1..e9c19b64bb5 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/SmartContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/SmartContextLoader.java @@ -27,13 +27,13 @@ import org.springframework.context.ApplicationContext; public interface SmartContextLoader extends ContextLoader { /** - * TODO Document processContextConfigurationAttributes(). + * TODO Document processContextConfiguration(). */ - void processContextConfigurationAttributes(ContextConfigurationAttributes configAttributes); + void processContextConfiguration(ContextConfigurationAttributes configAttributes); /** * TODO Document loadContext(). */ - ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration) throws Exception; + ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception; } diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java index e5f77a6cc19..a43ce9a2b56 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractContextLoader.java @@ -42,9 +42,9 @@ import org.springframework.util.StringUtils; public abstract class AbstractContextLoader implements SmartContextLoader { /** - * TODO Document processContextConfigurationAttributes(). + * TODO Document processContextConfiguration(). */ - public void processContextConfigurationAttributes(ContextConfigurationAttributes configAttributes) { + public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { String[] processedLocations = processLocations(configAttributes.getDeclaringClass(), configAttributes.getLocations()); diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java index c6aac51f74e..a7e0d9ca039 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/support/AbstractGenericContextLoader.java @@ -52,17 +52,16 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader * * @see SmartContextLoader#loadContext(MergedContextConfiguration) */ - public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration) - throws Exception { + public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { if (logger.isDebugEnabled()) { logger.debug(String.format("Loading ApplicationContext for merged context configuration [%s].", - mergedContextConfiguration)); + mergedConfig)); } GenericApplicationContext context = new GenericApplicationContext(); - context.getEnvironment().setActiveProfiles(mergedContextConfiguration.getActiveProfiles()); + context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles()); prepareContext(context); customizeBeanFactory(context.getDefaultListableBeanFactory()); - loadBeanDefinitions(context, mergedContextConfiguration); + loadBeanDefinitions(context, mergedConfig); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); context.refresh(); @@ -149,13 +148,12 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader * and override this method to provide a custom strategy for loading or * registering bean definitions. * @param context the context into which the bean definitions should be loaded - * @param mergedContextConfiguration TODO Document parameters. + * @param mergedConfig TODO Document parameters. * @since 3.1 * @see #loadContext */ - protected void loadBeanDefinitions(GenericApplicationContext context, - MergedContextConfiguration mergedContextConfiguration) { - createBeanDefinitionReader(context).loadBeanDefinitions(mergedContextConfiguration.getLocations()); + protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) { + createBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations()); } /** diff --git a/org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java b/org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java index e8aaac12797..d68477c635d 100644 --- a/org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java +++ b/org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.support.BeanDefinitionReader; import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; +import org.springframework.context.annotation.Configuration; import org.springframework.context.support.GenericApplicationContext; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.MergedContextConfiguration; @@ -43,14 +44,12 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader /** - * TODO Document overridden processContextConfigurationAttributes(). - * - * @see org.springframework.test.context.SmartContextLoader#processContextConfigurationAttributes + * TODO Document overridden processContextConfiguration(). */ - public void processContextConfigurationAttributes(ContextConfigurationAttributes configAttributes) { + public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { if (ObjectUtils.isEmpty(configAttributes.getClasses()) && isGenerateDefaultClasses()) { - Class>[] defaultConfigurationClasses = generateDefaultConfigurationClasses(configAttributes.getDeclaringClass()); - configAttributes.setClasses(defaultConfigurationClasses); + Class>[] defaultConfigClasses = generateDefaultConfigurationClasses(configAttributes.getDeclaringClass()); + configAttributes.setClasses(defaultConfigClasses); } } @@ -87,6 +86,8 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader /** * TODO Document isGenerateDefaultClasses(). + *
+ * TODO Consider renaming to a generic boolean generatesDefaults() method and moving to SmartContextLoader.
*/
protected boolean isGenerateDefaultClasses() {
return true;
@@ -101,7 +102,7 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
* class name refers to a nested static class within the
* test class.
*
- * @see #generateDefaultLocations(Class)
+ * @see #generateDefaultConfigurationClasses(Class)
*/
protected String getConfigurationClassNameSuffix() {
return "$ContextConfiguration";
@@ -118,10 +119,18 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader
List