From a77cf0f6523c3bd509ce017d9177e1fe5e043581 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 19 Jun 2011 17:36:25 +0000 Subject: [PATCH] [SPR-8395][SPR-8386] AnnotationConfigContextLoader now generates a list of default configuration classes by finding all non-private, non-final, static, inner classes of the test class that are annotated with @Configuration; updated JavaDoc in AbstractGenericContextLoader and AnnotationConfigContextLoader to reflect changes resulting from the SmartContextLoader integration. --- .../support/AbstractGenericContextLoader.java | 124 +++++++--- .../AnnotationConfigContextLoader.java | 219 +++++++++++------- .../AnnotationConfigContextLoaderTests.java | 53 +++-- ...ontextConfigurationInnerClassTestCase.java | 6 - .../FinalConfigInnerClassTestCase.java | 35 +++ ...pleStaticConfigurationClassesTestCase.java | 38 +++ .../NonStaticConfigInnerClassesTestCase.java | 40 ++++ ...ainVanillaFooConfigInnerClassTestCase.java | 7 - .../PrivateConfigInnerClassTestCase.java | 36 +++ 9 files changed, 410 insertions(+), 148 deletions(-) create mode 100644 org.springframework.test/src/test/java/org/springframework/test/context/support/FinalConfigInnerClassTestCase.java create mode 100644 org.springframework.test/src/test/java/org/springframework/test/context/support/MultipleStaticConfigurationClassesTestCase.java create mode 100644 org.springframework.test/src/test/java/org/springframework/test/context/support/NonStaticConfigInnerClassesTestCase.java create mode 100644 org.springframework.test/src/test/java/org/springframework/test/context/support/PrivateConfigInnerClassTestCase.java 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 35fdd6a3feb..55b392c4262 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 @@ -24,23 +24,36 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigUtils; import org.springframework.context.support.GenericApplicationContext; import org.springframework.test.context.MergedContextConfiguration; -import org.springframework.test.context.SmartContextLoader; import org.springframework.util.StringUtils; /** - * Abstract, generic extension of {@link AbstractContextLoader} which loads a - * {@link GenericApplicationContext} from the locations provided to - * {@link #loadContext loadContext()}. + * Abstract, generic extension of {@link AbstractContextLoader} that loads a + * {@link GenericApplicationContext}. + * + * * *

Concrete subclasses must provide an appropriate implementation of * {@link #createBeanDefinitionReader createBeanDefinitionReader()}, * potentially overriding {@link #loadBeanDefinitions loadBeanDefinitions()} - * in addition. + * as well. * * @author Sam Brannen * @author Juergen Hoeller * @since 2.5 - * @see #loadContext + * @see #loadContext(MergedContextConfiguration) + * @see #loadContext(String...) */ public abstract class AbstractGenericContextLoader extends AbstractContextLoader { @@ -48,9 +61,31 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** - * TODO Document loadContext(MergedContextConfiguration). - * - * @see SmartContextLoader#loadContext(MergedContextConfiguration) + * Load a Spring ApplicationContext from the supplied {@link MergedContextConfiguration}. + *

Implementation details: + *

+ * @return a new application context + * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration) + * @see GenericApplicationContext */ public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { if (logger.isDebugEnabled()) { @@ -70,7 +105,7 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader } /** - * Loads a Spring ApplicationContext from the supplied locations. + * Load a Spring ApplicationContext from the supplied locations. *

Implementation details: *

+ *

Note: this method does not provide a means to set active bean definition + * profiles for the loaded context. See {@link #loadContext(MergedContextConfiguration)} + * for an alternative. * @return a new application context * @see org.springframework.test.context.ContextLoader#loadContext * @see GenericApplicationContext + * @see #loadContext(MergedContextConfiguration) */ public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { if (logger.isDebugEnabled()) { @@ -110,58 +150,65 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Prepare the {@link GenericApplicationContext} created by this ContextLoader. - * Called before bean definitions are read. + * Called before bean definitions are read. *

The default implementation is empty. Can be overridden in subclasses to - * customize GenericApplicationContext's standard settings. - * @param context the context for which the BeanDefinitionReader should be created - * @see #loadContext - * @see org.springframework.context.support.GenericApplicationContext#setResourceLoader - * @see org.springframework.context.support.GenericApplicationContext#setId + * customize GenericApplicationContext's standard settings. + * @param context the context that should be prepared + * @see #loadContext(MergedContextConfiguration) + * @see #loadContext(String...) + * @see GenericApplicationContext#setAllowBeanDefinitionOverriding + * @see GenericApplicationContext#setResourceLoader + * @see GenericApplicationContext#setId */ protected void prepareContext(GenericApplicationContext context) { } /** - * Customize the internal bean factory of the ApplicationContext created by this ContextLoader. + * Customize the internal bean factory of the ApplicationContext created by + * this ContextLoader. *

The default implementation is empty but can be overridden in subclasses - * to customize DefaultListableBeanFactory's standard settings. + * to customize DefaultListableBeanFactory's standard settings. * @param beanFactory the bean factory created by this ContextLoader - * @see #loadContext - * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowBeanDefinitionOverriding(boolean) - * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowEagerClassLoading(boolean) - * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowCircularReferences(boolean) - * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping(boolean) + * @see #loadContext(MergedContextConfiguration) + * @see #loadContext(String...) + * @see DefaultListableBeanFactory#setAllowBeanDefinitionOverriding + * @see DefaultListableBeanFactory#setAllowEagerClassLoading + * @see DefaultListableBeanFactory#setAllowCircularReferences + * @see DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping */ protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory) { } /** * Load bean definitions into the supplied {@link GenericApplicationContext context} - * from the specified resource locations. + * from the configuration locations or classes in the supplied + * MergedContextConfiguration. *

The default implementation delegates to the {@link BeanDefinitionReader} - * returned by {@link #createBeanDefinitionReader} to + * returned by {@link #createBeanDefinitionReader()} to * {@link BeanDefinitionReader#loadBeanDefinitions(String) load} the * bean definitions. *

Subclasses must provide an appropriate implementation of - * {@link #createBeanDefinitionReader}. Alternatively subclasses may - * provide a no-op implementation of {@link #createBeanDefinitionReader} + * {@link #createBeanDefinitionReader()}. Alternatively subclasses may + * provide a no-op implementation of {@code createBeanDefinitionReader()} * 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 mergedConfig TODO Document mergedConfig parameter. + * @param mergedConfig the merged context configuration * @since 3.1 - * @see #loadContext + * @see #loadContext(MergedContextConfiguration) */ protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) { createBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations()); } /** - * Factory method for creating a new {@link BeanDefinitionReader} for - * loading bean definitions into the supplied {@link GenericApplicationContext context}. - * @param context the context for which the BeanDefinitionReader should be created - * @return a BeanDefinitionReader for the supplied context + * Factory method for creating a new {@link BeanDefinitionReader} for loading + * bean definitions into the supplied {@link GenericApplicationContext context}. + * @param context the context for which the BeanDefinitionReader + * should be created + * @return a BeanDefinitionReader for the supplied context * @see #loadContext(String...) + * @see #loadBeanDefinitions * @see BeanDefinitionReader */ protected abstract BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context); @@ -169,11 +216,12 @@ public abstract class AbstractGenericContextLoader extends AbstractContextLoader /** * Customize the {@link GenericApplicationContext} created by this * ContextLoader after bean definitions have been - * loaded into the context but before the context is refreshed. + * loaded into the context but before the context is refreshed. *

The default implementation is empty but can be overridden in subclasses * to customize the application context. * @param context the newly created application context - * @see #loadContext + * @see #loadContext(MergedContextConfiguration) + * @see #loadContext(String...) */ protected void customizeContext(GenericApplicationContext context) { } 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 d68477c635d..b720e30f631 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 @@ -16,6 +16,7 @@ package org.springframework.test.context.support; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; @@ -31,131 +32,124 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - * Concrete implementation of {@link AbstractGenericContextLoader} which - * registers bean definitions from + * Concrete implementation of {@link AbstractGenericContextLoader} that loads + * bean definitions from * {@link org.springframework.context.annotation.Configuration configuration classes}. * + *

Note: AnnotationConfigContextLoader supports + * {@link org.springframework.context.annotation.Configuration configuration classes} + * rather than the String-based resource locations defined by the legacy + * {@link org.springframework.test.context.ContextLoader ContextLoader} API. Thus, + * although AnnotationConfigContextLoader extends + * AbstractGenericContextLoader, AnnotationConfigContextLoader + * does not support any String-based methods defined by + * AbstractContextLoader or AbstractGenericContextLoader. + * Consequently, AnnotationConfigContextLoader should chiefly be + * considered a {@link org.springframework.test.context.SmartContextLoader SmartContextLoader} + * rather than a {@link org.springframework.test.context.ContextLoader ContextLoader}. + * * @author Sam Brannen * @since 3.1 + * @see #generateDefaultConfigurationClasses + * @see #loadBeanDefinitions */ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader { private static final Log logger = LogFactory.getLog(AnnotationConfigContextLoader.class); + // --- SmartContextLoader ----------------------------------------------- + /** * TODO Document overridden processContextConfiguration(). + * + * @see org.springframework.test.context.SmartContextLoader#processContextConfiguration + * @see #generatesDefaults + * @see #generateDefaultConfigurationClasses */ public void processContextConfiguration(ContextConfigurationAttributes configAttributes) { - if (ObjectUtils.isEmpty(configAttributes.getClasses()) && isGenerateDefaultClasses()) { + if (ObjectUtils.isEmpty(configAttributes.getClasses()) && generatesDefaults()) { Class[] defaultConfigClasses = generateDefaultConfigurationClasses(configAttributes.getDeclaringClass()); configAttributes.setClasses(defaultConfigClasses); } } - /** - * TODO Update documentation regarding SmartContextLoader SPI. - * - *

- * Registers {@link org.springframework.context.annotation.Configuration configuration classes} - * in the supplied {@link GenericApplicationContext context} from the specified - * class names. - * - *

Each class name must be the fully qualified class name of an - * annotated configuration class, component, or feature specification. An - * {@link AnnotatedBeanDefinitionReader} is used to register the appropriate - * bean definitions. - * - *

Note that this method does not call {@link #createBeanDefinitionReader} - * since AnnotatedBeanDefinitionReader is not an instance of - * {@link BeanDefinitionReader}. - * - * @param context the context in which the configuration classes should be registered - * @param classNames the names of configuration classes to register in the context - * @throws IllegalArgumentException if a supplied class name does not represent a class - */ - @Override - protected void loadBeanDefinitions(GenericApplicationContext context, - MergedContextConfiguration mergedContextConfiguration) { - Class[] configClasses = mergedContextConfiguration.getClasses(); - if (logger.isDebugEnabled()) { - logger.debug("Registering configuration classes: " + ObjectUtils.nullSafeToString(configClasses)); - } - new AnnotatedBeanDefinitionReader(context).register(configClasses); + // --- AnnotationConfigContextLoader --------------------------------------- + + private boolean isStaticNonPrivateAndNonFinal(Class clazz) { + Assert.notNull(clazz, "Class must not be null"); + int modifiers = clazz.getModifiers(); + return (Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)); } /** - * TODO Document isGenerateDefaultClasses(). - *

- * TODO Consider renaming to a generic boolean generatesDefaults() method and moving to SmartContextLoader. + * Determine if the supplied {@link Class} meets the criteria for being considered + * as a default configuration class candidate. + *

Specifically, such candidates: + *

+ * + * @param clazz the class the check + * @return true if the supplied class meets the candidate criteria */ - protected boolean isGenerateDefaultClasses() { + private boolean isDefaultConfigurationClassCandidate(Class clazz) { + return clazz != null && isStaticNonPrivateAndNonFinal(clazz) && clazz.isAnnotationPresent(Configuration.class); + } + + /** + * TODO Document generatesDefaults(). + */ + // TODO Consider moving to SmartContextLoader SPI. + protected boolean generatesDefaults() { return true; } - /** - * Returns "$ContextConfiguration"; intended to be used - * as a suffix to append to the name of the test class when generating - * default configuration class names. - * - *

Note: the use of a dollar sign ($) signifies that the resulting - * class name refers to a nested static class within the - * test class. - * - * @see #generateDefaultConfigurationClasses(Class) - */ - protected String getConfigurationClassNameSuffix() { - return "$ContextConfiguration"; - } - /** * TODO Document generateDefaultConfigurationClasses(). */ protected Class[] generateDefaultConfigurationClasses(Class declaringClass) { Assert.notNull(declaringClass, "Declaring class must not be null"); - String suffix = getConfigurationClassNameSuffix(); - Assert.hasText(suffix, "Configuration class name suffix must not be empty"); - String className = declaringClass.getName() + suffix; List> configClasses = new ArrayList>(); - try { - Class configClass = (Class) getClass().getClassLoader().loadClass(className); - if (configClass.isAnnotationPresent(Configuration.class)) { + + for (Class configClass : declaringClass.getDeclaredClasses()) { + if (isDefaultConfigurationClassCandidate(configClass)) { configClasses.add(configClass); } else { - logger.warn(String.format( - "Found candidate configuration class [%s], but it is not annotated with @Configuration.", className)); + if (logger.isDebugEnabled()) { + logger.debug(String.format( + "Ignoring class [%s]; it must be static, non-private, non-final, and annotated " + + "with @Configuration to be considered a default configuration class.", + configClass.getName())); + } } } - catch (ClassNotFoundException e) { + + if (configClasses.isEmpty()) { logger.warn(String.format( - "Cannot load @Configuration class with generated class name [%s]: class not found", className)); + "Test class [%s] does not declare any static, non-private, non-final, inner classes annotated " + + "with @Configuration that can be used as a default configuration class.", declaringClass)); } return configClasses.toArray(new Class[configClasses.size()]); } - /** - * TODO Document overridden createBeanDefinitionReader(). - */ - @Override - protected BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context) { - throw new UnsupportedOperationException( - "AnnotationConfigContextLoader does not support the createBeanDefinitionReader(GenericApplicationContext) method"); - } + // --- AbstractContextLoader ----------------------------------------------- /** - * TODO Document overridden generateDefaultLocations(). - */ - @Override - protected String[] generateDefaultLocations(Class clazz) { - throw new UnsupportedOperationException( - "AnnotationConfigContextLoader does not support the generateDefaultLocations(Class) method"); - } - - /** - * TODO Document overridden modifyLocations(). + * AnnotationConfigContextLoader should be used as a + * {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}, + * not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}. + * Consequently, this method is not supported. + * + * @see AbstractContextLoader#modifyLocations + * @throws UnsupportedOperationException */ @Override protected String[] modifyLocations(Class clazz, String... locations) { @@ -164,7 +158,28 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader } /** - * TODO Document overridden getResourceSuffix(). + * AnnotationConfigContextLoader should be used as a + * {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}, + * not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}. + * Consequently, this method is not supported. + * + * @see AbstractContextLoader#generateDefaultLocations + * @throws UnsupportedOperationException + */ + @Override + protected String[] generateDefaultLocations(Class clazz) { + throw new UnsupportedOperationException( + "AnnotationConfigContextLoader does not support the generateDefaultLocations(Class) method"); + } + + /** + * AnnotationConfigContextLoader should be used as a + * {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}, + * not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}. + * Consequently, this method is not supported. + * + * @see AbstractContextLoader#getResourceSuffix + * @throws UnsupportedOperationException */ @Override protected String getResourceSuffix() { @@ -172,4 +187,48 @@ public class AnnotationConfigContextLoader extends AbstractGenericContextLoader "AnnotationConfigContextLoader does not support the getResourceSuffix() method"); } + // --- AbstractGenericContextLoader ---------------------------------------- + + /** + * Register {@link org.springframework.context.annotation.Configuration configuration classes} + * in the supplied {@link GenericApplicationContext context} from the classes + * in the supplied {@link MergedContextConfiguration}. + * + *

Each class must represent an annotated configuration class or component. An + * {@link AnnotatedBeanDefinitionReader} is used to register the appropriate + * bean definitions. + * + *

Note that this method does not call {@link #createBeanDefinitionReader} + * since AnnotatedBeanDefinitionReader is not an instance of + * {@link BeanDefinitionReader}. + * + * @param context the context in which the configuration classes should be registered + * @param mergedConfig the merged configuration from which the classes should be retrieved + * @see AbstractGenericContextLoader#loadBeanDefinitions + */ + @Override + protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) { + Class[] configClasses = mergedConfig.getClasses(); + if (logger.isDebugEnabled()) { + logger.debug("Registering configuration classes: " + ObjectUtils.nullSafeToString(configClasses)); + } + new AnnotatedBeanDefinitionReader(context).register(configClasses); + } + + /** + * AnnotationConfigContextLoader should be used as a + * {@link org.springframework.test.context.SmartContextLoader SmartContextLoader}, + * not as a legacy {@link org.springframework.test.context.ContextLoader ContextLoader}. + * Consequently, this method is not supported. + * + * @see #loadBeanDefinitions + * @see AbstractGenericContextLoader#createBeanDefinitionReader + * @throws UnsupportedOperationException + */ + @Override + protected BeanDefinitionReader createBeanDefinitionReader(GenericApplicationContext context) { + throw new UnsupportedOperationException( + "AnnotationConfigContextLoader does not support the createBeanDefinitionReader(GenericApplicationContext) method"); + } + } diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java index 636bed78d36..1a6bd2c4da3 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/AnnotationConfigContextLoaderTests.java @@ -32,31 +32,50 @@ public class AnnotationConfigContextLoaderTests { private final AnnotationConfigContextLoader contextLoader = new AnnotationConfigContextLoader(); - // Developer's note: AnnotationConfigContextLoader currently generates a - // default config class named exactly ContextConfiguration, which is a - // static inner class of the test class itself. - @Test - public void generateDefaultConfigurationClassesForAnnotatedInnerClassNamedContextConfiguration() { - Class[] defaultLocations = contextLoader.generateDefaultConfigurationClasses(ContextConfigurationInnerClassTestCase.class); - assertNotNull(defaultLocations); - assertEquals("ContextConfigurationInnerClassTestCase.ContextConfiguration should be found", 1, - defaultLocations.length); + public void generateDefaultConfigurationClassesForAnnotatedInnerClass() { + Class[] configClasses = contextLoader.generateDefaultConfigurationClasses(ContextConfigurationInnerClassTestCase.class); + assertNotNull(configClasses); + assertEquals("annotated static ContextConfiguration should be considered.", 1, configClasses.length); + + configClasses = contextLoader.generateDefaultConfigurationClasses(AnnotatedFooConfigInnerClassTestCase.class); + assertNotNull(configClasses); + assertEquals("annotated static FooConfig should be considered.", 1, configClasses.length); } @Test - public void generateDefaultConfigurationClassesForAnnotatedInnerClass() { - Class[] defaultLocations = contextLoader.generateDefaultConfigurationClasses(AnnotatedFooConfigInnerClassTestCase.class); - assertNotNull(defaultLocations); - assertEquals("AnnotatedFooConfigInnerClassTestCase.FooConfig should NOT be found", 0, defaultLocations.length); + public void generateDefaultConfigurationClassesForMultipleAnnotatedInnerClasses() { + Class[] configClasses = contextLoader.generateDefaultConfigurationClasses(MultipleStaticConfigurationClassesTestCase.class); + assertNotNull(configClasses); + assertEquals("multiple annotated static classes should be considered.", 2, configClasses.length); } @Test public void generateDefaultConfigurationClassesForNonAnnotatedInnerClass() { - Class[] defaultLocations = contextLoader.generateDefaultConfigurationClasses(PlainVanillaFooConfigInnerClassTestCase.class); - assertNotNull(defaultLocations); - assertEquals("PlainVanillaFooConfigInnerClassTestCase.FooConfig should NOT be found", 0, - defaultLocations.length); + Class[] configClasses = contextLoader.generateDefaultConfigurationClasses(PlainVanillaFooConfigInnerClassTestCase.class); + assertNotNull(configClasses); + assertEquals("non-annotated static FooConfig should NOT be considered.", 0, configClasses.length); + } + + @Test + public void generateDefaultConfigurationClassesForFinalAnnotatedInnerClass() { + Class[] configClasses = contextLoader.generateDefaultConfigurationClasses(FinalConfigInnerClassTestCase.class); + assertNotNull(configClasses); + assertEquals("final annotated static Config should NOT be considered.", 0, configClasses.length); + } + + @Test + public void generateDefaultConfigurationClassesForPrivateAnnotatedInnerClass() { + Class[] configClasses = contextLoader.generateDefaultConfigurationClasses(PrivateConfigInnerClassTestCase.class); + assertNotNull(configClasses); + assertEquals("private annotated inner classes should NOT be considered.", 0, configClasses.length); + } + + @Test + public void generateDefaultConfigurationClassesForNonStaticAnnotatedInnerClass() { + Class[] configClasses = contextLoader.generateDefaultConfigurationClasses(NonStaticConfigInnerClassesTestCase.class); + assertNotNull(configClasses); + assertEquals("non-static annotated inner classes should NOT be considered.", 0, configClasses.length); } } diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/ContextConfigurationInnerClassTestCase.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/ContextConfigurationInnerClassTestCase.java index 54734f15c52..5d243200033 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/context/support/ContextConfigurationInnerClassTestCase.java +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/ContextConfigurationInnerClassTestCase.java @@ -16,7 +16,6 @@ package org.springframework.test.context.support; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** @@ -30,11 +29,6 @@ public class ContextConfigurationInnerClassTestCase { @Configuration static class ContextConfiguration { - - @Bean - public String foo() { - return "foo"; - } } } diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/FinalConfigInnerClassTestCase.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/FinalConfigInnerClassTestCase.java new file mode 100644 index 00000000000..89a1653b09f --- /dev/null +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/FinalConfigInnerClassTestCase.java @@ -0,0 +1,35 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.support; + +import org.springframework.context.annotation.Configuration; + +/** + * Not an actual test case. + * + * @author Sam Brannen + * @since 3.1 + * @see AnnotationConfigContextLoaderTests + */ +public class FinalConfigInnerClassTestCase { + + // Intentionally FINAL. + @Configuration + static final class Config { + } + +} diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/MultipleStaticConfigurationClassesTestCase.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/MultipleStaticConfigurationClassesTestCase.java new file mode 100644 index 00000000000..a07dc16cfa5 --- /dev/null +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/MultipleStaticConfigurationClassesTestCase.java @@ -0,0 +1,38 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.support; + +import org.springframework.context.annotation.Configuration; + +/** + * Not an actual test case. + * + * @author Sam Brannen + * @since 3.1 + * @see AnnotationConfigContextLoaderTests + */ +public class MultipleStaticConfigurationClassesTestCase { + + @Configuration + static class ConfigA { + } + + @Configuration + static class ConfigB { + } + +} diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/NonStaticConfigInnerClassesTestCase.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/NonStaticConfigInnerClassesTestCase.java new file mode 100644 index 00000000000..a7118532417 --- /dev/null +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/NonStaticConfigInnerClassesTestCase.java @@ -0,0 +1,40 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.support; + +import org.springframework.context.annotation.Configuration; + +/** + * Not an actual test case. + * + * @author Sam Brannen + * @since 3.1 + * @see AnnotationConfigContextLoaderTests + */ +public class NonStaticConfigInnerClassesTestCase { + + // Intentionally not static + @Configuration + class FooConfig { + } + + // Intentionally not static + @Configuration + class BarConfig { + } + +} diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/PlainVanillaFooConfigInnerClassTestCase.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/PlainVanillaFooConfigInnerClassTestCase.java index 0588ff037ce..98858425fa1 100644 --- a/org.springframework.test/src/test/java/org/springframework/test/context/support/PlainVanillaFooConfigInnerClassTestCase.java +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/PlainVanillaFooConfigInnerClassTestCase.java @@ -16,8 +16,6 @@ package org.springframework.test.context.support; -import org.springframework.context.annotation.Bean; - /** * Not an actual test case. * @@ -29,11 +27,6 @@ public class PlainVanillaFooConfigInnerClassTestCase { // Intentionally NOT annotated with @Configuration static class FooConfig { - - @Bean - public String foo() { - return "foo"; - } } } diff --git a/org.springframework.test/src/test/java/org/springframework/test/context/support/PrivateConfigInnerClassTestCase.java b/org.springframework.test/src/test/java/org/springframework/test/context/support/PrivateConfigInnerClassTestCase.java new file mode 100644 index 00000000000..ad90a740678 --- /dev/null +++ b/org.springframework.test/src/test/java/org/springframework/test/context/support/PrivateConfigInnerClassTestCase.java @@ -0,0 +1,36 @@ +/* + * Copyright 2011 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.test.context.support; + +import org.springframework.context.annotation.Configuration; + +/** + * Not an actual test case. + * + * @author Sam Brannen + * @since 3.1 + * @see AnnotationConfigContextLoaderTests + */ +public class PrivateConfigInnerClassTestCase { + + // Intentionally private + @SuppressWarnings("unused") + @Configuration + private static class PrivateConfig { + } + +}