@Test
public void testFailureAndSuccess() throws Exception {

    URL url = getUniqueURL(PATH_TO_RESOURCE);
    // The server stops responding
    Mockito.doNothing().when(server.getHandler()).handle(any(), any(), any(), any());
    // First request throws exception, because a get request is sent
    try {
        testClient.get(url);
    } catch (IOException e) {
        assertThat(e, instanceOf(IOException.class));
        assertThat(e.getMessage(), equalTo("Unable to get " + url.toString()));
        assertThat(e.getCause(), instanceOf(FileNotFoundException.class));
    }
    mockHandler(server.getHandler());
    // Next requests do not throw exception
    assertNull(testClient.get(url));
    assertNull(testClient.get(url));
    verify(server.getHandler(), times(1)).handle(any(), any(), any(), any());
}