Browse Source

Revert to previous behavior for 7.0.2 (based on Boot/Data impact)

Preparing the revised behavior for 7.1 instead.

See gh-31456
pull/36004/head
Juergen Hoeller 7 days ago
parent
commit
e2c9dc7138
  1. 3
      spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java
  2. 2
      spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesBaseTests.java
  3. 11
      spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesInheritedTests.java
  4. 6
      spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DefaultContextConfigurationDetectionWithNestedTests.java

3
spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java

@ -252,7 +252,8 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot
CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) {
List<ContextConfigurationAttributes> defaultConfigAttributesList = List<ContextConfigurationAttributes> defaultConfigAttributesList =
ContextLoaderUtils.resolveDefaultContextConfigurationAttributes(testClass); Collections.singletonList(new ContextConfigurationAttributes(testClass));
// for 7.1: ContextLoaderUtils.resolveDefaultContextConfigurationAttributes(testClass);
ContextLoader contextLoader = resolveContextLoader(testClass, defaultConfigAttributesList); ContextLoader contextLoader = resolveContextLoader(testClass, defaultConfigAttributesList);
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {

2
spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesBaseTests.java

@ -41,6 +41,7 @@ class ImplicitDefaultConfigClassesBaseTests {
@Autowired @Autowired
String greeting1; String greeting1;
@Test @Test
void greeting1() { void greeting1() {
// This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration. // This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration.
@ -49,6 +50,7 @@ class ImplicitDefaultConfigClassesBaseTests {
assertThat(greeting1).isEqualTo("TEST 1"); assertThat(greeting1).isEqualTo("TEST 1");
} }
@Configuration @Configuration
static class DefaultConfig { static class DefaultConfig {

11
spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesInheritedTests.java

@ -40,6 +40,13 @@ class ImplicitDefaultConfigClassesInheritedTests extends ImplicitDefaultConfigCl
@Autowired @Autowired
String greeting2; String greeting2;
// To be removed in favor of base class method in 7.1
@Test
void greeting1() {
assertThat(greeting1).isEqualTo("TEST 2");
}
@Test @Test
void greeting2() { void greeting2() {
// This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration. // This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration.
@ -50,9 +57,11 @@ class ImplicitDefaultConfigClassesInheritedTests extends ImplicitDefaultConfigCl
@Test @Test
void greetings(@Autowired List<String> greetings) { void greetings(@Autowired List<String> greetings) {
assertThat(greetings).containsExactly("TEST 1", "TEST 2"); assertThat(greetings).containsExactly("TEST 2");
// for 7.1: assertThat(greetings).containsExactly("TEST 1", "TEST 2");
} }
@Configuration @Configuration
static class DefaultConfig { static class DefaultConfig {

6
spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DefaultContextConfigurationDetectionWithNestedTests.java

@ -16,7 +16,6 @@
package org.springframework.test.context.junit.jupiter.nested; package org.springframework.test.context.junit.jupiter.nested;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
@ -43,6 +42,7 @@ class DefaultContextConfigurationDetectionWithNestedTests {
@Autowired @Autowired
String greeting; String greeting;
@Test @Test
void test(@Autowired String localGreeting) { void test(@Autowired String localGreeting) {
// This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration. // This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration.
@ -52,6 +52,8 @@ class DefaultContextConfigurationDetectionWithNestedTests {
assertThat(localGreeting).isEqualTo("TEST"); assertThat(localGreeting).isEqualTo("TEST");
} }
/** for 7.1:
@Nested @Nested
class NestedTests { class NestedTests {
@ -61,6 +63,8 @@ class DefaultContextConfigurationDetectionWithNestedTests {
assertThat(localGreeting).isEqualTo("TEST"); assertThat(localGreeting).isEqualTo("TEST");
} }
} }
*/
@Configuration @Configuration
static class DefaultConfig { static class DefaultConfig {

Loading…
Cancel
Save