@Test
public void makeCall_shouldReuseWrappedInvocationBuilderReference_whenBmcExceptionIsThrown()
        throws Exception {

    // Set up WrappedInvocationBuilder used to verify
    URI requestURI = PowerMockito.mock(URI.class);
    final WrappedInvocationBuilder expectedWIb = mock(WrappedInvocationBuilder.class);
    final Invocation.Builder ib = mock(Invocation.Builder.class);
    whenNew(WrappedInvocationBuilder.class)
            .withArguments(ib, requestURI)
            .thenReturn(expectedWIb);
    final Response expectedResponse = mock(Response.class);
    // Stub exceptions thrown by the client 3 consecutive times then a successful
    when(
                    mockFederationClient.post(
                            Mockito.<WrappedInvocationBuilder>any(),
                            Mockito.<X509FederationClient.X509FederationRequest>any(),
                            Mockito.<BmcRequest>any()))
            .thenThrow(new BmcException(409, "ServiceCode", "Exception 1", "RequestId"))
            .thenThrow(new BmcException(409, "ServiceCode", "Exception 2", "RequestId"))
            .thenThrow(new BmcException(409, "ServiceCode", "Exception 3", "RequestId"))
            .thenReturn(expectedResponse);
    // Method under test.
    final Response actualResponse =
            clientUnderTest.makeCall(
                    ib, requestURI, mock(X509FederationClient.X509FederationRequest.class));
    assertEquals("Response should be equal", expectedResponse, actualResponse);
    verify(mockFederationClient, times(4))
            .post(
                    wrappedIbCaptor.capture(),
                    isA(X509FederationClient.X509FederationRequest.class),
                    isA(BmcRequest.class));
    final List<WrappedInvocationBuilder> wrappedIbsFromInvocation =
            wrappedIbCaptor.getAllValues();
    assertFalse(
            "Captured list of WrappedInvocationBuilder should not be empty",
            wrappedIbsFromInvocation.isEmpty());
    assertEquals(
            "Captured list of WrappedInvocationBuilder size should be 4",
            4 /* expected number of captures */,
            wrappedIbsFromInvocation.size());
    for (WrappedInvocationBuilder actualWib : wrappedIbsFromInvocation) {
        assertEquals("Captured WIB should be the same", expectedWIb, actualWib);
    }
}