Skip to content

Commit 0dc44f7

Browse files
committed
Avoid superfluous MergedContextConfiguration equals() check
See gh-36390
1 parent f481f99 commit 0dc44f7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@
7979
*/
8080
public abstract class AbstractTestContextBootstrapper implements TestContextBootstrapper {
8181

82+
private static final String IGNORED_DEFAULT_CONFIG_MESSAGE = """
83+
For test class [%1$s], the following 'default' context configuration %2$s were detected \
84+
but are currently ignored: %3$s. In Spring Framework 7.1, these %2$s will no longer be ignored. \
85+
Please update your test configuration accordingly. For details, see: \
86+
https://docs.spring.io/spring-framework/reference/testing/testcontext-framework/ctx-management/default-config.html""";
87+
88+
8289
private final Log logger = LogFactory.getLog(getClass());
8390

8491
private @Nullable BootstrapContext bootstrapContext;
@@ -290,28 +297,25 @@ private void logWarningForIgnoredDefaultConfig(MergedContextConfiguration merged
290297
MergedContextConfiguration completeMergedConfig = buildMergedContextConfiguration(
291298
testClass, completeDefaultConfigAttributesList, contextLoader, null,
292299
cacheAwareContextLoaderDelegate, false);
293-
if (!mergedConfig.equals(completeMergedConfig)) {
294-
String warningMessage = """
295-
For test class [%1$s], the following 'default' context configuration %2$s were \
296-
detected but are currently ignored: %3$s. In Spring Framework 7.1, these %2$s will no \
297-
longer be ignored. Please update your test configuration accordingly. For details, see: \
298-
https://docs.spring.io/spring-framework/reference/testing/testcontext-framework/ctx-management/default-config.html""";
299300

301+
if (!Arrays.equals(mergedConfig.getClasses(), completeMergedConfig.getClasses())) {
300302
Set<Class<?>> currentClasses = new HashSet<>(Arrays.asList(mergedConfig.getClasses()));
301303
String ignoredClasses = Arrays.stream(completeMergedConfig.getClasses())
302304
.filter(clazz -> !currentClasses.contains(clazz))
303305
.map(Class::getName)
304306
.collect(Collectors.joining(", "));
305307
if (!ignoredClasses.isEmpty()) {
306-
logger.warn(warningMessage.formatted(testClass.getName(), "classes", ignoredClasses));
308+
logger.warn(IGNORED_DEFAULT_CONFIG_MESSAGE.formatted(testClass.getName(), "classes", ignoredClasses));
307309
}
310+
}
308311

312+
if (!Arrays.equals(mergedConfig.getLocations(), completeMergedConfig.getLocations())) {
309313
Set<String> currentLocations = new HashSet<>(Arrays.asList(mergedConfig.getLocations()));
310314
String ignoredLocations = Arrays.stream(completeMergedConfig.getLocations())
311315
.filter(location -> !currentLocations.contains(location))
312316
.collect(Collectors.joining(", "));
313317
if (!ignoredLocations.isEmpty()) {
314-
logger.warn(warningMessage.formatted(testClass.getName(), "locations", ignoredLocations));
318+
logger.warn(IGNORED_DEFAULT_CONFIG_MESSAGE.formatted(testClass.getName(), "locations", ignoredLocations));
315319
}
316320
}
317321
}

0 commit comments

Comments
 (0)