mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-20 06:29:16 +00:00
Add nullability annotations to tests in module/spring-boot-micrometer-tracing
See gh-47263
This commit is contained in:
@@ -66,3 +66,11 @@ dependencies {
|
||||
testRuntimeOnly("ch.qos.logback:logback-classic")
|
||||
testRuntimeOnly("io.grpc:grpc-api")
|
||||
}
|
||||
|
||||
tasks.named("compileTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
||||
tasks.named("compileDockerTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
||||
+5
-2
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import brave.propagation.Propagation;
|
||||
import brave.propagation.TraceContext;
|
||||
import brave.propagation.TraceContextOrSamplingFlags;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
@@ -92,7 +93,9 @@ class CompositePropagationFactoryTests {
|
||||
Propagation<String> propagation = factory.get();
|
||||
Map<String, String> request = Map.of("a", "a-value", "b", "b-value");
|
||||
TraceContextOrSamplingFlags context = propagation.extractor(new MapGetter()).extract(request);
|
||||
assertThat(context.context().extra()).containsExactly("a");
|
||||
TraceContext traceContext = context.context();
|
||||
assertThat(traceContext).isNotNull();
|
||||
assertThat(traceContext.extra()).containsExactly("a");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,7 +130,7 @@ class CompositePropagationFactoryTests {
|
||||
private static final class MapGetter implements Propagation.Getter<Map<String, String>, String> {
|
||||
|
||||
@Override
|
||||
public String get(Map<String, String> request, String key) {
|
||||
public @Nullable String get(Map<String, String> request, String key) {
|
||||
return request.get(key);
|
||||
}
|
||||
|
||||
|
||||
+4
-3
@@ -29,6 +29,7 @@ import io.opentelemetry.context.propagation.TextMapGetter;
|
||||
import io.opentelemetry.context.propagation.TextMapPropagator;
|
||||
import io.opentelemetry.context.propagation.TextMapSetter;
|
||||
import io.opentelemetry.extension.trace.propagation.B3Propagator;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
@@ -147,7 +148,7 @@ class CompositeTextMapPropagatorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Map<String, String> carrier, String key) {
|
||||
public @Nullable String get(@Nullable Map<String, String> carrier, String key) {
|
||||
if (carrier == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -173,12 +174,12 @@ class CompositeTextMapPropagatorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <C> void inject(Context context, C carrier, TextMapSetter<C> setter) {
|
||||
public <C> void inject(Context context, @Nullable C carrier, TextMapSetter<C> setter) {
|
||||
setter.set(carrier, this.field, this.field + "-value");
|
||||
}
|
||||
|
||||
@Override
|
||||
public <C> Context extract(Context context, C carrier, TextMapGetter<C> getter) {
|
||||
public <C> Context extract(Context context, @Nullable C carrier, TextMapGetter<C> getter) {
|
||||
String value = getter.get(carrier, this.field);
|
||||
if (value != null) {
|
||||
return context.with(this.contextKeyRegistry.get(this.field), value);
|
||||
|
||||
+3
-1
@@ -25,6 +25,7 @@ import brave.propagation.Propagation.Factory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link LocalBaggageFields}.
|
||||
@@ -52,8 +53,9 @@ class LocalBaggageFieldsTests {
|
||||
private static FactoryBuilder createBuilder() {
|
||||
return BaggagePropagation.newFactoryBuilder(new Factory() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Propagation<String> get() {
|
||||
return null;
|
||||
return mock(Propagation.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+2
-1
@@ -275,7 +275,8 @@ class MicrometerTracingAutoConfigurationTests {
|
||||
|
||||
@Bean
|
||||
SpanTagAnnotationHandler spanTagAnnotationHandler() {
|
||||
return new SpanTagAnnotationHandler((valueResolverClass) -> null, (valueExpressionResolverClass) -> null);
|
||||
return new SpanTagAnnotationHandler((valueResolverClass) -> mock(ValueResolver.class),
|
||||
(valueExpressionResolverClass) -> mock(ValueExpressionResolver.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ package org.springframework.boot.micrometer.tracing.autoconfigure.prometheus;
|
||||
import io.micrometer.tracing.Span;
|
||||
import io.micrometer.tracing.TraceContext;
|
||||
import io.micrometer.tracing.Tracer;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -46,7 +47,7 @@ class LazyTracingSpanContextTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tracer getObject(Object... args) throws BeansException {
|
||||
public Tracer getObject(@Nullable Object... args) throws BeansException {
|
||||
return LazyTracingSpanContextTests.this.tracer;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ import brave.Tag;
|
||||
import brave.handler.MutableSpan;
|
||||
import brave.handler.SpanHandler;
|
||||
import brave.propagation.TraceContext;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import zipkin2.reporter.BytesEncoder;
|
||||
import zipkin2.reporter.BytesMessageSender;
|
||||
@@ -186,7 +187,7 @@ class ZipkinConfigurationsBraveConfigurationTests {
|
||||
Tag<Throwable> throwableTag() {
|
||||
return new Tag<>("exception") {
|
||||
@Override
|
||||
protected String parseValue(Throwable throwable, TraceContext traceContext) {
|
||||
protected @Nullable String parseValue(Throwable throwable, @Nullable TraceContext traceContext) {
|
||||
return throwable.getMessage();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user