@Test public void testGet() throws Exception { MockResponse mockResponse = new MockResponse() .setBody(TEST_RESPONSE_BODY) .setResponseCode(StatusCode.OK.getCode()); server.enqueue(mockResponse); HttpClient client = OkHttpClient.newBuilder() .build(); Request request = new Request.Builder() .url(server.url("/").toString()) .get() .build(); Response response = client.execute(request); Assertions.assertThat(response.isSuccessful()).isTrue(); InputStream inputStream = response.getBody().get(InputStream.class); String actualResponseBody = CharStreams.toString(new InputStreamReader(inputStream, Charsets.UTF_8)); Assertions.assertThat(actualResponseBody).isEqualTo(TEST_RESPONSE_BODY); RecordedRequest recordedRequest = server.takeRequest(1, TimeUnit.MILLISECONDS); Assertions.assertThat(recordedRequest).isNotNull(); Assertions.assertThat(recordedRequest.getBodySize()).isLessThanOrEqualTo(0); }
@Override public Response get(String url) { Request request = new Request.Builder() .url(url) .get() .build(); return execute(request); }
OkHttpClient implements HttpClient { @Override public Response get(String url) { Request request = new Request.Builder() .url(url) .get() .build(); return execute(request); } }
OkHttpClient implements HttpClient { @Override public Response get(String url) { Request request = new Request.Builder() .url(url) .get() .build(); return execute(request); } OkHttpClient(Builder builder); }
OkHttpClient implements HttpClient { @Override public Response get(String url) { Request request = new Request.Builder() .url(url) .get() .build(); return execute(request); } OkHttpClient(Builder builder); @Override Response execute(Request request); @Override Response get(String url); @Override Response head(String url); @Override Response post(String url, Object entity); @Override Response delete(String url); @Override Response delete(String url, Object entity); @Override Response put(String url, Object entity); @Override Response patch(String url, Object entity); SSLContext sslContext(); X509TrustManager trustManager(); List<Interceptor> interceptors(); static Builder newBuilder(); static Builder newBuilder(OkHttpClient okHttpClient); }
OkHttpClient implements HttpClient { @Override public Response get(String url) { Request request = new Request.Builder() .url(url) .get() .build(); return execute(request); } OkHttpClient(Builder builder); @Override Response execute(Request request); @Override Response get(String url); @Override Response head(String url); @Override Response post(String url, Object entity); @Override Response delete(String url); @Override Response delete(String url, Object entity); @Override Response put(String url, Object entity); @Override Response patch(String url, Object entity); SSLContext sslContext(); X509TrustManager trustManager(); List<Interceptor> interceptors(); static Builder newBuilder(); static Builder newBuilder(OkHttpClient okHttpClient);  }