HttpHandler implements AutoCloseable { public HttpResponse post(String path, HttpEntity entity) throws IOException { HttpPost post = new HttpPost(url.resolve(path)); creds.ifPresent(x -> post.setHeader("Authorization", "Basic " + x)); post.setEntity(entity); return client.execute(post); } HttpHandler(URI url, OnrampOptions options); HttpResponse get(String path); HttpResponse post(String path, HttpEntity entity); @Override void close(); static HttpHandler paver(OnrampOptions options); static HttpHandler onramp(OnrampOptions options);  }
@Test public void simplePost() throws Exception { stubFor(post(urlEqualTo("/foo")).willReturn(aResponse().withStatus(HttpStatus.SC_OK).withBody("bar"))); try (HttpHandler handler = new HttpHandler(url, options)) { HttpEntity entity = EntityBuilder.create().setText("baz").build(); HttpResponse response = handler.post("foo", entity); try (Reader reader = new InputStreamReader(response.getEntity().getContent())) { assertThat(CharStreams.toString(reader), is("bar")); } } verify(postRequestedFor(urlEqualTo("/foo")).withRequestBody(equalTo("baz"))); }