Skip to content

Commit

Permalink
Improve error message for wrong version of micrometer-observation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sbrannen committed Jul 3, 2023
1 parent 5aac35b commit 07fe8ee
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.test.context.observation;

import java.lang.reflect.Method;

import io.micrometer.observation.ObservationRegistry;
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
import org.apache.commons.logging.Log;
Expand All @@ -25,6 +27,7 @@
import org.springframework.core.Conventions;
import org.springframework.test.context.TestContext;
import org.springframework.test.context.support.AbstractTestExecutionListener;
import org.springframework.util.ReflectionUtils;

/**
* {@code TestExecutionListener} which provides support for Micrometer's
Expand Down Expand Up @@ -80,7 +83,10 @@ class MicrometerObservationRegistryTestExecutionListener extends AbstractTestExe
Class.forName(classToCheck, false, classLoader);
classToCheck = OBSERVATION_THREAD_LOCAL_ACCESSOR_CLASS_NAME;
Class<?> clazz = Class.forName(classToCheck, false, classLoader);
clazz.getMethod("getObservationRegistry");
Method method = ReflectionUtils.findMethod(clazz, "getObservationRegistry");
if (method == null) {
errorMessage = classToCheck + ". Method getObservationRegistry() not found. " + DEPENDENCIES_ERROR_MESSAGE;
}
}
catch (Throwable ex) {
errorMessage = classToCheck + ". " + DEPENDENCIES_ERROR_MESSAGE;
Expand Down

0 comments on commit 07fe8ee

Please sign in to comment.