Fix OkHttp tests · micrometer-metrics/micrometer@55b8f06 (original) (raw)

`@@ -22,17 +22,16 @@

`

22

22

`import io.micrometer.core.instrument.Tags;

`

23

23

`import io.micrometer.core.instrument.simple.SimpleConfig;

`

24

24

`import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

`

25

``

`-

import okhttp3.Cache;

`

26

``

`-

import okhttp3.OkHttpClient;

`

27

``

`-

import okhttp3.Request;

`

28

``

`-

import okhttp3.Response;

`

``

25

`+

import okhttp3.*;

`

29

26

`import org.junit.jupiter.api.Test;

`

30

27

`import org.junit.jupiter.api.extension.ExtendWith;

`

31

28

`import org.junit.jupiter.api.io.TempDir;

`

``

29

`+

import org.testcontainers.shaded.org.checkerframework.checker.nullness.qual.Nullable;

`

32

30

`import ru.lanwen.wiremock.ext.WiremockResolver;

`

33

31

``

34

32

`import java.io.IOException;

`

35

33

`import java.nio.file.Path;

`

``

34

`+

import java.util.Optional;

`

36

35

`import java.util.concurrent.TimeUnit;

`

37

36

`import java.util.function.Function;

`

38

37

``

`@@ -53,9 +52,9 @@ class OkHttpMetricsEventListenerTest {

`

53

52

``

54

53

`private static final String URI_EXAMPLE_VALUE = "uriExample";

`

55

54

``

56

``

`-

private static final Function<Request, String> URI_MAPPER = req -> URI_EXAMPLE_VALUE;

`

``

55

`+

private static final Function<@Nullable Request, String> URI_MAPPER = req -> URI_EXAMPLE_VALUE;

`

57

56

``

58

``

`-

private MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

`

``

57

`+

private final MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

`

59

58

``

60

59

`private OkHttpClient client = new OkHttpClient.Builder()

`

61

60

` .eventListener(OkHttpMetricsEventListener.builder(registry, "okhttp.requests")

`

`@@ -146,7 +145,7 @@ void uriTagWorksWithUriMapper(@WiremockResolver.Wiremock WireMockServer server)

`

146

145

`server.stubFor(any(anyUrl()));

`

147

146

`OkHttpClient client = new OkHttpClient.Builder()

`

148

147

` .eventListener(OkHttpMetricsEventListener.builder(registry, "okhttp.requests")

`

149

``

`-

.uriMapper(req -> req.url().encodedPath())

`

``

148

`+

.uriMapper(req -> Optional.ofNullable(req).map(Request::url).map(HttpUrl::encodedPath).orElse("null"))

`

150

149

` .tags(Tags.of("foo", "bar"))

`

151

150

` .build())

`

152

151

` .build();

`

`@@ -167,7 +166,8 @@ void contextSpecificTags(@WiremockResolver.Wiremock WireMockServer server) throw

`

167

166

`server.stubFor(any(anyUrl()));

`

168

167

`OkHttpClient client = new OkHttpClient.Builder()

`

169

168

` .eventListener(OkHttpMetricsEventListener.builder(registry, "okhttp.requests")

`

170

``

`-

.tag((req, res) -> Tag.of("another.uri", req.url().encodedPath()))

`

``

169

`+

.tag((req, res) -> Tag.of("another.uri",

`

``

170

`+

Optional.ofNullable(req).map(Request::url).map(HttpUrl::encodedPath).orElse("null")))

`

171

171

` .build())

`

172

172

` .build();

`

173

173

``

`@@ -268,7 +268,7 @@ private void testRequestTags(@WiremockResolver.Wiremock WireMockServer server, R

`

268

268

`server.stubFor(any(anyUrl()));

`

269

269

`OkHttpClient client = new OkHttpClient.Builder()

`

270

270

` .eventListener(OkHttpMetricsEventListener.builder(registry, "okhttp.requests")

`

271

``

`-

.uriMapper(req -> req.url().encodedPath())

`

``

271

`+

.uriMapper(req -> Optional.ofNullable(req).map(Request::url).map(HttpUrl::encodedPath).orElse("null"))

`

272

272

` .tags(Tags.of("foo", "bar"))

`

273

273

` .build())

`

274

274

` .build();

`