diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java index 06162f25e41..d5a654935db 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AbstractTestContextBootstrapper.java @@ -20,11 +20,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -80,13 +78,6 @@ import org.springframework.util.StringUtils; */ public abstract class AbstractTestContextBootstrapper implements TestContextBootstrapper { - private static final String IGNORED_DEFAULT_CONFIG_MESSAGE = """ - For test class [%1$s], the following 'default' context configuration %2$s were detected \ - but are currently ignored: %3$s. In Spring Framework 7.1, these %2$s will no longer be ignored. \ - Please update your test configuration accordingly. For details, see: \ - https://docs.spring.io/spring-framework/reference/testing/testcontext-framework/ctx-management/default-config.html"""; - - private final Log logger = LogFactory.getLog(getClass()); private @Nullable BootstrapContext bootstrapContext; @@ -262,12 +253,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { List defaultConfigAttributesList = - Collections.singletonList(new ContextConfigurationAttributes(testClass)); - // for 7.1: ContextLoaderUtils.resolveDefaultContextConfigurationAttributes(testClass); - + ContextLoaderUtils.resolveDefaultContextConfigurationAttributes(testClass); MergedContextConfiguration mergedConfig = buildMergedContextConfiguration( testClass, defaultConfigAttributesList, null, cacheAwareContextLoaderDelegate, false); - logWarningForIgnoredDefaultConfig(mergedConfig, cacheAwareContextLoaderDelegate); if (logger.isTraceEnabled()) { logger.trace(String.format( @@ -283,46 +271,6 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot return mergedConfig; } - /** - * In Spring Framework 7.1, we will use the "complete" list of default config attributes. - * In the interim, we log a warning if the "current" detected config differs from the - * "complete" detected config, which signals that some default configuration is currently - * being ignored. - */ - private void logWarningForIgnoredDefaultConfig(MergedContextConfiguration mergedConfig, - CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate) { - - if (logger.isWarnEnabled()) { - Class testClass = mergedConfig.getTestClass(); - List completeDefaultConfigAttributesList = - ContextLoaderUtils.resolveDefaultContextConfigurationAttributes(testClass); - MergedContextConfiguration completeMergedConfig = buildMergedContextConfiguration( - testClass, completeDefaultConfigAttributesList, null, - cacheAwareContextLoaderDelegate, false); - - if (!Arrays.equals(mergedConfig.getClasses(), completeMergedConfig.getClasses())) { - Set> currentClasses = new HashSet<>(Arrays.asList(mergedConfig.getClasses())); - String ignoredClasses = Arrays.stream(completeMergedConfig.getClasses()) - .filter(clazz -> !currentClasses.contains(clazz)) - .map(Class::getName) - .collect(Collectors.joining(", ")); - if (!ignoredClasses.isEmpty()) { - logger.warn(IGNORED_DEFAULT_CONFIG_MESSAGE.formatted(testClass.getName(), "classes", ignoredClasses)); - } - } - - if (!Arrays.equals(mergedConfig.getLocations(), completeMergedConfig.getLocations())) { - Set currentLocations = new HashSet<>(Arrays.asList(mergedConfig.getLocations())); - String ignoredLocations = Arrays.stream(completeMergedConfig.getLocations()) - .filter(location -> !currentLocations.contains(location)) - .collect(Collectors.joining(", ")); - if (!ignoredLocations.isEmpty()) { - logger.warn(IGNORED_DEFAULT_CONFIG_MESSAGE.formatted(testClass.getName(), "locations", ignoredLocations)); - } - } - } - } - /** * Build the {@linkplain MergedContextConfiguration merged context configuration} * for the supplied {@link Class testClass}, context configuration attributes, diff --git a/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesBaseTests.java b/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesBaseTests.java index 36c2718f47a..1828e0df7c9 100644 --- a/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesBaseTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesBaseTests.java @@ -46,7 +46,7 @@ class ImplicitDefaultConfigClassesBaseTests { @Test - void greeting1AndPuzzle1() { + final void greeting1AndPuzzle1() { // This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration. assertThat(AnnotatedElementUtils.hasAnnotation(getClass(), ContextConfiguration.class)).isFalse(); diff --git a/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesInheritedTests.java b/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesInheritedTests.java index 93699c072ce..7a33a39c882 100644 --- a/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesInheritedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/config/ImplicitDefaultConfigClassesInheritedTests.java @@ -41,14 +41,6 @@ class ImplicitDefaultConfigClassesInheritedTests extends ImplicitDefaultConfigCl String greeting2; - // To be removed in favor of base class method in 7.1 - @Test - @Override - void greeting1AndPuzzle1() { - assertThat(greeting1).isEqualTo("TEST 2"); - assertThat(puzzle1).isEqualTo(222); - } - @Test void greeting2() { // This class must NOT be annotated with @SpringJUnitConfig or @ContextConfiguration. @@ -59,8 +51,7 @@ class ImplicitDefaultConfigClassesInheritedTests extends ImplicitDefaultConfigCl @Test void greetings(@Autowired List greetings) { - assertThat(greetings).containsExactly("TEST 2"); - // for 7.1: assertThat(greetings).containsExactly("TEST 1", "TEST 2"); + assertThat(greetings).containsExactly("TEST 1", "TEST 2"); } diff --git a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DefaultContextConfigurationDetectionWithNestedTests.java b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DefaultContextConfigurationDetectionWithNestedTests.java index 615c2355837..8e1d361f342 100644 --- a/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DefaultContextConfigurationDetectionWithNestedTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/junit/jupiter/nested/DefaultContextConfigurationDetectionWithNestedTests.java @@ -16,6 +16,7 @@ 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.extension.ExtendWith; @@ -53,7 +54,6 @@ class DefaultContextConfigurationDetectionWithNestedTests { } - /** for 7.1: @Nested class NestedTests { @@ -63,7 +63,6 @@ class DefaultContextConfigurationDetectionWithNestedTests { assertThat(localGreeting).isEqualTo("TEST"); } } - */ @Configuration