HTTPClientImpl implements HTTPClient { @Override public HTTPResponse execute(HTTPRequest request) { var watch = new StopWatch(); Request httpRequest = httpRequest(request); try (Response httpResponse = client.newCall(httpRequest).execute()) { return response(httpResponse); } catch (IOException e) { throw new HTTPClientException(Strings.format("http request failed, uri={}, error={}", request.uri, e.getMessage()), "HTTP_REQUEST_FAILED", e); } finally { long elapsed = watch.elapsed(); ActionLogContext.track("http", elapsed); logger.debug("execute, elapsed={}", elapsed); if (elapsed > slowOperationThresholdInNanos(request)) { logger.warn(errorCode("SLOW_HTTP"), "slow http operation, method={}, uri={}, elapsed={}", request.method, request.uri, Duration.ofNanos(elapsed)); } } } HTTPClientImpl(OkHttpClient client, String userAgent, Duration slowOperationThreshold); @Override HTTPResponse execute(HTTPRequest request);  }
@Test void execute() throws IOException { Response httpResponse = new Response.Builder().request(new Request.Builder().url("http: .protocol(Protocol.HTTP_1_1).code(200).message("OK") .header("content-type", "text/html") .body(ResponseBody.create(Strings.bytes("<html/>"), MediaType.get("text/html"))) .build(); Call call = mock(Call.class); when(okHttpClient.newCall(any())).thenReturn(call); when(call.execute()).thenReturn(httpResponse); HTTPResponse response = httpClient.execute(new HTTPRequest(HTTPMethod.GET, "http: assertThat(response.statusCode).isEqualTo(200); }