FutureOkHttpClient implements AutoCloseable { static Request forUri(HttpUrl uri, String method, Object payload) { try { return internalForUri(uri, method, Json.serialize(payload)); } catch (JsonProcessingException e) { throw new RuntimeException(e); } } private  FutureOkHttpClient(OkHttpClient client); @Override void close();  }
@Test public void testMethod() { final Request request = FutureOkHttpClient.forUri(URI, "DELETE"); assertThat(request.url(), is(URI)); assertThat(request.method(), is("DELETE")); }
@Test public void testUnserializablePayload() { class EmptyClass {} thrown.expectCause(instanceOf(JsonProcessingException.class)); FutureOkHttpClient.forUri(URI, "POST", new EmptyClass()); }
@Test public void testRequestWithBody() { final Request request = FutureOkHttpClient.forUri(URI, "POST", Arrays.asList(1, 2, 3)); assertThat(request.url(), is(URI)); assertThat(request.method(), is("POST")); assertThat(bytesOfRequestBody(request), is(ByteString.encodeUtf8("[1,2,3]"))); }