[SPR-8386] AnnotationConfigContextLoader now only considers static inner classes annotated with @Configuration when generating default configuration classes.
This commit is contained in:
parent
46639c5a1d
commit
d904bcbf03
|
|
@ -20,10 +20,13 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Not an actual <em>test case</em>.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
* @see AnnotationConfigContextLoaderTests
|
||||
*/
|
||||
public class FooConfigInnerClassTestCase {
|
||||
public class AnnotatedFooConfigInnerClassTestCase {
|
||||
|
||||
@Configuration
|
||||
static class FooConfig {
|
||||
|
|
@ -32,19 +32,31 @@ public class AnnotationConfigContextLoaderTests {
|
|||
private final AnnotationConfigContextLoader contextLoader = new AnnotationConfigContextLoader();
|
||||
|
||||
|
||||
@Test
|
||||
public void generateDefaultConfigurationClassesWithFailure() {
|
||||
Class<?>[] defaultLocations = contextLoader.generateDefaultConfigurationClasses(FooConfigInnerClassTestCase.class);
|
||||
assertNotNull(defaultLocations);
|
||||
assertEquals("FooConfigInnerClassTestCase.FooConfig should NOT be found", 0, defaultLocations.length);
|
||||
}
|
||||
// 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 generateDefaultConfigurationClassesWithSuccess() {
|
||||
public void generateDefaultConfigurationClassesForAnnotatedInnerClassNamedContextConfiguration() {
|
||||
Class<?>[] defaultLocations = contextLoader.generateDefaultConfigurationClasses(ContextConfigurationInnerClassTestCase.class);
|
||||
assertNotNull(defaultLocations);
|
||||
assertEquals("ContextConfigurationInnerClassTestCase.ContextConfiguration should be found", 1,
|
||||
defaultLocations.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateDefaultConfigurationClassesForAnnotatedInnerClass() {
|
||||
Class<?>[] defaultLocations = contextLoader.generateDefaultConfigurationClasses(AnnotatedFooConfigInnerClassTestCase.class);
|
||||
assertNotNull(defaultLocations);
|
||||
assertEquals("AnnotatedFooConfigInnerClassTestCase.FooConfig should NOT be found", 0, defaultLocations.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateDefaultConfigurationClassesForNonAnnotatedInnerClass() {
|
||||
Class<?>[] defaultLocations = contextLoader.generateDefaultConfigurationClasses(PlainVanillaFooConfigInnerClassTestCase.class);
|
||||
assertNotNull(defaultLocations);
|
||||
assertEquals("PlainVanillaFooConfigInnerClassTestCase.FooConfig should NOT be found", 0,
|
||||
defaultLocations.length);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,11 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* Not an actual <em>test case</em>.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
* @see AnnotationConfigContextLoaderTests
|
||||
*/
|
||||
public class ContextConfigurationInnerClassTestCase {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* 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.Bean;
|
||||
|
||||
/**
|
||||
* Not an actual <em>test case</em>.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
* @see AnnotationConfigContextLoaderTests
|
||||
*/
|
||||
public class PlainVanillaFooConfigInnerClassTestCase {
|
||||
|
||||
// Intentionally NOT annotated with @Configuration
|
||||
static class FooConfig {
|
||||
|
||||
@Bean
|
||||
public String foo() {
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue