@Test
public void testExecuteUnauthorizedThenSuccess() throws Exception {

    when(mockResponse.getStatusLine())
        .thenReturn(HTTP_401_STATUSLINE)
        .thenReturn(HTTP_200_STATUSLINE)
        .thenReturn(HTTP_200_STATUSLINE);
    when(httpClient.execute(eq(HTTP_HOST), HttpRequestMatcher.eq(request), eq(httpClientContext)))
        .thenReturn(mockResponse)
        .thenReturn(mockResponse);
    when(httpClient.execute(eq(HTTP_HOST), HttpRequestMatcher.eq(loginRequest), eq(httpClientContext)))
        .thenReturn(mockResponse);
    final CloseableHttpResponse response = client.execute(request);
    assertThat(response, notNullValue());
    assertThat(response, sameInstance(mockResponse));
    verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(request), eq(0));
    verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(loginRequest), eq(401));
    verifyPrivate(client).invoke("execute", HttpRequestMatcher.eq(request), eq(200));
}