From 29248dff15fda93f2b590bfb9c8f9a7a8aec55cd Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 22 Jun 2023 15:43:38 +0200 Subject: [PATCH] Use correct ClassLoader in MicrometerObservationRegistryTestExecutionListener In the original implementation of MicrometerObservationRegistryTestExecutionListener I accidentally imported JUnit 5's org.junit.platform.launcher.TestExecutionListener instead Spring's org.springframework.test.context.TestExecutionListener. The code therefore attempts to use the ClassLoader for the JUnit Platform's TestExecutionListener which may fail to see the required types. In addition, if the JUnit Platform's TestExecutionListener is not on the classpath, the attempt to access its ClassLoader will fail. This commit addresses this by properly using the ClassLoader for Spring's TestExecutionListener to detect dependencies of the MicrometerObservationRegistryTestExecutionListener. Closes gh-30726 --- .../MicrometerObservationRegistryTestExecutionListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java index 97873c1a09..e408242889 100644 --- a/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java @@ -22,11 +22,11 @@ import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.platform.launcher.TestExecutionListener; import org.springframework.context.ApplicationContext; import org.springframework.core.Conventions; import org.springframework.test.context.TestContext; +import org.springframework.test.context.TestExecutionListener; import org.springframework.test.context.support.AbstractTestExecutionListener; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils;