@Test
public void shouldRetryConnectionAfterExceptionDuringReconnection() throws IOException, InterruptedException, BackoffException {

    final Response response = mock(Response.class);
    final ByteArrayInputStream initialInputStream = new ByteArrayInputStream("{\"cursor\":{\"partition\":\"0\",\"offset\":\"0\"}}".getBytes("utf-8"));
    when(response.getBody()).thenReturn(initialInputStream);
    final Request request = mock(Request.class);
    when(request.execute()).thenReturn(response).thenThrow(new IOException("Reconnection failed")).thenReturn(response).thenThrow(new IOException("Reconnection failed on second attempt"));
    when(RequestFactory.createRequest(uri, "GET")).thenReturn(request);
    final ExponentialBackoffStrategy backoffStrategy = new EqualJitterBackoffStrategy(1, 1, 2, 4);
    final NakadiReader<SomeEvent> nakadiReader = new NakadiReader<>(uri, RequestFactory, backoffStrategy, cursorManager, objectMapper, Collections.singleton(EVENT_NAME), Optional.empty(), Optional.empty(), SomeEvent.class, listener);
    expectedException.expect(BackoffException.class);
    expectedException.expect(ComposeMatchers.hasFeature(BackoffException::getRetries, equalTo(4)));
    expectedException.expectCause(instanceOf(IOException.class));
    expectedException.expectCause(ComposeMatchers.hasFeature("message", Exception::getMessage, Matchers.containsString("Reconnection failed on second attempt")));
    nakadiReader.runInternal();
}