Add nullability annotations to tests in module/spring-boot-micrometer-observation

See gh-47263
This commit is contained in:
Moritz Halbritter
2025-10-13 13:44:08 +02:00
parent 54b663eb69
commit 0c43462c66
3 changed files with 15 additions and 3 deletions
@@ -36,3 +36,7 @@ dependencies {
testRuntimeOnly("ch.qos.logback:logback-classic")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
@@ -115,7 +115,9 @@ class ObservationAutoConfigurationTests {
Observation observation = Observation.start("filtered", observationRegistry);
observation.stop();
observation.getContext().getLowCardinalityKeyValues().forEach((kv) -> System.out.println(kv.getKey()));
assertThat(observation.getContext().getLowCardinalityKeyValue("filter").getValue()).isEqualTo("one");
KeyValue filter = observation.getContext().getLowCardinalityKeyValue("filter");
assertThat(filter).isNotNull();
assertThat(filter.getValue()).isEqualTo("one");
});
}
@@ -131,7 +133,9 @@ class ObservationAutoConfigurationTests {
ObservationRegistry observationRegistry = context.getBean(ObservationRegistry.class);
Observation observation = Observation.start("keyvalues", observationRegistry);
observation.stop();
assertThat(observation.getContext().getLowCardinalityKeyValue("a").getValue()).isEqualTo("alpha");
KeyValue a = observation.getContext().getLowCardinalityKeyValue("a");
assertThat(a).isNotNull();
assertThat(a.getValue()).isEqualTo("alpha");
});
}
@@ -86,8 +86,12 @@ class ObservationHandlerGroupsTests {
@SuppressWarnings("unchecked")
private static List<ObservationHandler<?>> getObservationHandlers(ObservationConfig config) {
Method method = ReflectionUtils.findMethod(ObservationConfig.class, "getObservationHandlers");
assertThat(method).isNotNull();
ReflectionUtils.makeAccessible(method);
return (List<ObservationHandler<?>>) ReflectionUtils.invokeMethod(method, config);
List<ObservationHandler<?>> observationHandlers = (List<ObservationHandler<?>>) ReflectionUtils
.invokeMethod(method, config);
assertThat(observationHandlers).isNotNull();
return observationHandlers;
}
private static class NamedObservationHandler implements ObservationHandler<Observation.Context> {