Skip to content

Commit 07fe8ee

Browse files
committed
Improve error message for wrong version of micrometer-observation
This commit also reverts to using ReflectionUtils.findMethod in order to make the check more robust in case the Micrometer team refactors the code base and declares the `getObservationRegistry()` method in a super type.
1 parent 5aac35b commit 07fe8ee

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.test.context.observation;
1818

19+
import java.lang.reflect.Method;
20+
1921
import io.micrometer.observation.ObservationRegistry;
2022
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
2123
import org.apache.commons.logging.Log;
@@ -25,6 +27,7 @@
2527
import org.springframework.core.Conventions;
2628
import org.springframework.test.context.TestContext;
2729
import org.springframework.test.context.support.AbstractTestExecutionListener;
30+
import org.springframework.util.ReflectionUtils;
2831

2932
/**
3033
* {@code TestExecutionListener} which provides support for Micrometer's
@@ -80,7 +83,10 @@ class MicrometerObservationRegistryTestExecutionListener extends AbstractTestExe
8083
Class.forName(classToCheck, false, classLoader);
8184
classToCheck = OBSERVATION_THREAD_LOCAL_ACCESSOR_CLASS_NAME;
8285
Class<?> clazz = Class.forName(classToCheck, false, classLoader);
83-
clazz.getMethod("getObservationRegistry");
86+
Method method = ReflectionUtils.findMethod(clazz, "getObservationRegistry");
87+
if (method == null) {
88+
errorMessage = classToCheck + ". Method getObservationRegistry() not found. " + DEPENDENCIES_ERROR_MESSAGE;
89+
}
8490
}
8591
catch (Throwable ex) {
8692
errorMessage = classToCheck + ". " + DEPENDENCIES_ERROR_MESSAGE;

0 commit comments

Comments
 (0)