Skip to content

Commit 7f88f31

Browse files
committed
Introduce logging for ContextCustomizer[Factory] to improve diagnostics
Prior to this commit, we logged which default TestExecutionListeners were discovered and which listeners were used, but we did not log anything for ContextCustomizerFactory and ContextCustomizer. This commit therefore introduces similar logging for ContextCustomizerFactory and ContextCustomizer to improve diagnostics. Closes gh-29036
1 parent aa7ef79 commit 7f88f31

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,10 @@ public final List<TestExecutionListener> getTestExecutionListeners() {
202202
protected List<TestExecutionListener> getDefaultTestExecutionListeners() {
203203
List<TestExecutionListener> listeners = SpringFactoriesLoader.forDefaultResourceLocation()
204204
.load(TestExecutionListener.class, this::handleListenerInstantiationFailure);
205-
206-
if (logger.isInfoEnabled()) {
207-
List<String> classNames = listeners.stream().map(Object::getClass).map(Class::getName).toList();
208-
logger.info("Loaded default TestExecutionListener implementations from location [%s]: %s"
209-
.formatted(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames));
205+
if (logger.isDebugEnabled()) {
206+
logger.debug("Loaded default TestExecutionListener implementations from location [%s]: %s"
207+
.formatted(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames(listeners)));
210208
}
211-
212209
return Collections.unmodifiableList(listeners);
213210
}
214211

@@ -426,6 +423,9 @@ private Set<ContextCustomizer> getContextCustomizers(Class<?> testClass,
426423
customizers.add(customizer);
427424
}
428425
}
426+
if (logger.isInfoEnabled()) {
427+
logger.info("Using ContextCustomizers: " + customizers);
428+
}
429429
return customizers;
430430
}
431431

@@ -438,7 +438,13 @@ private Set<ContextCustomizer> getContextCustomizers(Class<?> testClass,
438438
* @see SpringFactoriesLoader#loadFactories
439439
*/
440440
protected List<ContextCustomizerFactory> getContextCustomizerFactories() {
441-
return SpringFactoriesLoader.loadFactories(ContextCustomizerFactory.class, getClass().getClassLoader());
441+
List<ContextCustomizerFactory> factories =
442+
SpringFactoriesLoader.loadFactories(ContextCustomizerFactory.class, getClass().getClassLoader());
443+
if (logger.isDebugEnabled()) {
444+
logger.debug("Loaded ContextCustomizerFactory implementations from location [%s]: %s"
445+
.formatted(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames(factories)));
446+
}
447+
return factories;
442448
}
443449

444450
/**
@@ -562,6 +568,10 @@ protected MergedContextConfiguration processMergedContextConfiguration(MergedCon
562568
}
563569

564570

571+
private static List<String> classNames(List<?> components) {
572+
return components.stream().map(Object::getClass).map(Class::getName).toList();
573+
}
574+
565575
private static boolean areAllEmpty(Collection<?>... collections) {
566576
return Arrays.stream(collections).allMatch(Collection::isEmpty);
567577
}

0 commit comments

Comments
 (0)