Skip to content

Commit 39583d2

Browse files
committed
[SPR-6184] AnnotationConfigContextLoader now defines "$ContextConfiguration" as the resource suffix for generated default @configuration class names.
1 parent 16fc083 commit 39583d2

11 files changed

+60
-128
lines changed

org.springframework.test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoader.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,19 @@ protected String[] modifyLocations(Class<?> clazz, String... classNames) {
123123
}
124124

125125
/**
126-
* Returns &quot;Config</code>&quot;; intended to be used as a suffix
127-
* to append to the name of the test class when generating default
128-
* configuration class names.
126+
* Returns &quot;$ContextConfiguration</code>&quot;; intended to be used
127+
* as a suffix to append to the name of the test class when generating
128+
* default configuration class names.
129+
*
130+
* <p>Note: the use of a dollar sign ($) signifies that the resulting
131+
* class name refers to a nested <code>static</code> class within the
132+
* test class.
133+
*
129134
* @see #generateDefaultLocations(Class)
130135
*/
131136
@Override
132137
protected String getResourceSuffix() {
133-
return "Config";
138+
return "$ContextConfiguration";
134139
}
135140

136141
/**

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingDefaultConfigClassesInheritedTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import static org.junit.Assert.assertNotNull;
2121

2222
import org.junit.Test;
23+
import org.springframework.beans.Employee;
24+
import org.springframework.context.annotation.Bean;
25+
import org.springframework.context.annotation.Configuration;
2326
import org.springframework.test.context.ContextConfiguration;
2427

2528
/**
@@ -35,6 +38,20 @@
3538
@ContextConfiguration
3639
public class BeanOverridingDefaultConfigClassesInheritedTests extends DefaultConfigClassesBaseTests {
3740

41+
@Configuration
42+
static class ContextConfiguration {
43+
44+
@Bean
45+
public Employee employee() {
46+
Employee employee = new Employee();
47+
employee.setName("Yoda");
48+
employee.setAge(900);
49+
employee.setCompany("The Force");
50+
return employee;
51+
}
52+
}
53+
54+
3855
@Test
3956
@Override
4057
public void verifyEmployeeSetFromBaseContextConfig() {

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingDefaultConfigClassesInheritedTestsConfig.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/BeanOverridingExplicitConfigClassesInheritedTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @author Sam Brannen
3333
* @since 3.1
3434
*/
35-
@ContextConfiguration(classes = BeanOverridingDefaultConfigClassesInheritedTestsConfig.class)
35+
@ContextConfiguration(classes = BeanOverridingDefaultConfigClassesInheritedTests.ContextConfiguration.class)
3636
public class BeanOverridingExplicitConfigClassesInheritedTests extends ExplicitConfigClassesBaseTests {
3737

3838
@Test

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesBaseTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.junit.runner.RunWith;
2424
import org.springframework.beans.Employee;
2525
import org.springframework.beans.factory.annotation.Autowired;
26+
import org.springframework.context.annotation.Bean;
27+
import org.springframework.context.annotation.Configuration;
2628
import org.springframework.test.context.ContextConfiguration;
2729
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2830
import org.springframework.test.context.support.AnnotationConfigContextLoader;
@@ -40,6 +42,20 @@
4042
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
4143
public class DefaultConfigClassesBaseTests {
4244

45+
@Configuration
46+
static class ContextConfiguration {
47+
48+
@Bean
49+
public Employee employee() {
50+
Employee employee = new Employee();
51+
employee.setName("John Smith");
52+
employee.setAge(42);
53+
employee.setCompany("Acme Widgets, Inc.");
54+
return employee;
55+
}
56+
}
57+
58+
4359
@Autowired
4460
protected Employee employee;
4561

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesBaseTestsConfig.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesInheritedTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.junit.Test;
2323
import org.springframework.beans.Pet;
2424
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.context.annotation.Bean;
26+
import org.springframework.context.annotation.Configuration;
2527
import org.springframework.test.context.ContextConfiguration;
2628

2729
/**
@@ -37,6 +39,16 @@
3739
@ContextConfiguration
3840
public class DefaultConfigClassesInheritedTests extends DefaultConfigClassesBaseTests {
3941

42+
@Configuration
43+
static class ContextConfiguration {
44+
45+
@Bean
46+
public Pet pet() {
47+
return new Pet("Fido");
48+
}
49+
}
50+
51+
4052
@Autowired
4153
private Pet pet;
4254

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/DefaultConfigClassesInheritedTestsConfig.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesBaseTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @since 3.1
3838
*/
3939
@RunWith(SpringJUnit4ClassRunner.class)
40-
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesBaseTestsConfig.class)
40+
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesBaseTests.ContextConfiguration.class)
4141
public class ExplicitConfigClassesBaseTests {
4242

4343
@Autowired

org.springframework.test/src/test/java/org/springframework/test/context/junit4/annotation/ExplicitConfigClassesInheritedTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* @since 3.1
3939
*/
4040
@RunWith(SpringJUnit4ClassRunner.class)
41-
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesInheritedTestsConfig.class)
41+
@ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = DefaultConfigClassesInheritedTests.ContextConfiguration.class)
4242
public class ExplicitConfigClassesInheritedTests extends ExplicitConfigClassesBaseTests {
4343

4444
@Autowired

0 commit comments

Comments
 (0)