DefinitionSupplier implements Supplier<JsonNode>, AutoCloseable { @Override public JsonNode get() { try { HttpResponse response = handler.get("roads/" + roadName); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new RuntimeException("Error from Data Highway service: " + response.getStatusLine().toString()); } return objectMapper.readTree(response.getEntity().getContent()); } catch (IOException e) { throw new RuntimeException(e); } } DefinitionSupplier(OnrampOptions options); @Override JsonNode get(); @Override void close();  }
@Test public void getDefinition() throws IOException { HttpResponse response = response(HttpStatus.SC_OK, "{\"name\":\"test_road\"}"); when(handler.get(anyString())).thenReturn(response); JsonNode result = underTest.get(); assertThat(result.get("name").asText(), is(TEST_ROAD)); }
@Test(expected = RuntimeException.class) public void getDefinitionStatus500() throws IOException { HttpResponse response = response(HttpStatus.SC_INTERNAL_SERVER_ERROR, ""); when(handler.get(anyString())).thenReturn(response); underTest.get(); }