@Test
public void executeShouldRetryAndFailIfStatusCodeIsGreaterThan400() throws Exception {

    RequestException requestException1 = mock(RequestException.class);
    ArgumentCaptor<RequestException> requestException2 = ArgumentCaptor.forClass(RequestException.class);
    Response badResponse = mock(Response.class);
    when(badResponse.getStatusCode()).thenReturn(123);
    when(retryHandler.retry(requestException1, 2)).thenReturn(true);
    when(retryHandler.retry(requestException2.capture(), eq(3))).thenReturn(false);
    when(mockRequestExecutor.execute(request)).thenThrow(requestException1).thenReturn(badResponse);
    try {
        toTest.execute(request);
    } catch (Exception e) {
        assertSame(requestException2.getValue(), e);
        assertSame(badResponse, requestException2.getValue().getResponse());
        assertEquals("", requestException2.getValue().getMessage());
        verify(requestException1).dispose();
        verifyNoMoreInteractions(requestException2);
    }
}