From 7f88f315a40f20f45a4a1841018341729a6ea9c0 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 28 Aug 2022 16:08:38 +0200 Subject: [PATCH] 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 --- .../AbstractTestContextBootstrapper.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) 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 ec7c183ad5..d699a6f289 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 @@ -202,13 +202,10 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot protected List getDefaultTestExecutionListeners() { List listeners = SpringFactoriesLoader.forDefaultResourceLocation() .load(TestExecutionListener.class, this::handleListenerInstantiationFailure); - - if (logger.isInfoEnabled()) { - List classNames = listeners.stream().map(Object::getClass).map(Class::getName).toList(); - logger.info("Loaded default TestExecutionListener implementations from location [%s]: %s" - .formatted(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames)); + if (logger.isDebugEnabled()) { + logger.debug("Loaded default TestExecutionListener implementations from location [%s]: %s" + .formatted(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames(listeners))); } - return Collections.unmodifiableList(listeners); } @@ -426,6 +423,9 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot customizers.add(customizer); } } + if (logger.isInfoEnabled()) { + logger.info("Using ContextCustomizers: " + customizers); + } return customizers; } @@ -438,7 +438,13 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot * @see SpringFactoriesLoader#loadFactories */ protected List getContextCustomizerFactories() { - return SpringFactoriesLoader.loadFactories(ContextCustomizerFactory.class, getClass().getClassLoader()); + List factories = + SpringFactoriesLoader.loadFactories(ContextCustomizerFactory.class, getClass().getClassLoader()); + if (logger.isDebugEnabled()) { + logger.debug("Loaded ContextCustomizerFactory implementations from location [%s]: %s" + .formatted(SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames(factories))); + } + return factories; } /** @@ -562,6 +568,10 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot } + private static List classNames(List components) { + return components.stream().map(Object::getClass).map(Class::getName).toList(); + } + private static boolean areAllEmpty(Collection... collections) { return Arrays.stream(collections).allMatch(Collection::isEmpty); }