### Question:
HttpClientTransport implements RestTransport { @Segment(name = "transport", category = "network", library = "kamon") @Override public SagaResponse with(String address, String path, String method, Map<String, Map<String, String>> params) { URIBuilder builder = new URIBuilder().setScheme("http").setHost(address).setPath(path); if (params.containsKey("query")) { for (Entry<String, String> entry : params.get("query").entrySet()) { builder.addParameter(entry.getKey(), entry.getValue()); } } try { URI uri = builder.build(); Request request = requestFactories.getOrDefault( method.toUpperCase(), exceptionThrowingFunction(method)).apply(uri); request.socketTimeout(requestTimeout); if (params.containsKey("json")) { request.bodyString(params.get("json").get("body"), ContentType.APPLICATION_JSON); } if (params.containsKey("form")) { Form form = Form.form(); for (Entry<String, String> entry : params.get("form").entrySet()) { form.add(entry.getKey(), entry.getValue()).build(); } request.bodyForm(form.build()); } return this.on(request); } catch (URISyntaxException e) { throw new TransportFailedException("Wrong request URI", e); } } HttpClientTransport();  HttpClientTransport(int requestTimeout); @Segment(name = "transport", category = "network", library = "kamon") @Override SagaResponse with(String address, String path, String method, Map<String, Map<String, String>> params);  }### Answer:
@Test public void getsRequestFromRemote() { Map<String, Map<String, String>> requests = singletonMap("query", map("foo", "bar", "hello", "world")); SagaResponse response = transport.with(address, usableResource, "GET", requests); assertThat(response.succeeded(), is(true)); assertThat(response.body(), containsString(usableResponse)); }
@Test public void putsRequestToRemote() { Map<String, Map<String, String>> requests = new HashMap<>(); requests.put("query", singletonMap("foo", "bar")); requests.put("json", singletonMap("body", json)); SagaResponse response = transport.with(address, usableResource, "PUT", requests); assertThat(response.succeeded(), is(true)); assertThat(response.body(), containsString(usableResponse)); }
@Test public void blowsUpWhenRemoteResponseIsNot2XX() { Map<String, Map<String, String>> requests = new HashMap<>(); requests.put("query", singletonMap("foo", "bar")); requests.put("form", map("hello", "world", "jesus", "christ")); try { transport.with(address, faultyResource, "POST", requests); expectFailing(TransportFailedException.class); } catch (TransportFailedException e) { assertThat(e.getMessage(), containsString("The remote service returned with status code 500")); } }
@Test public void blowsUpWhenRemoteIsNotReachable() { try { transport.with("http: expectFailing(TransportFailedException.class); } catch (TransportFailedException e) { assertThat(e.getMessage(), is("Network Error")); } }
@Test public void blowsUpWhenMethodIsUnknown() { try { transport.with(address, usableResource, "Blah", emptyMap()); expectFailing(TransportFailedException.class); } catch (TransportFailedException e) { assertThat(e.getMessage(), is("No such method Blah")); } }
@Test public void blowsUpWhenUriIsMalformed() { try { transport.with("\\", usableResource, "GET", emptyMap()); expectFailing(TransportFailedException.class); } catch (TransportFailedException e) { assertThat(e.getMessage(), is("Wrong request URI")); } }
@Test public void blowsUpWhenRequestTimeout() { HttpClientTransport transportWithShortTimeout = new HttpClientTransport(1000); try { transportWithShortTimeout.with(address, slowResource, "GET", emptyMap()); expectFailing(TransportFailedException.class); } catch (TransportFailedException e) { assertThat(SocketTimeoutException.class.isInstance(e.getCause()), is(true)); } }