@Test
public void failoverIsExecutedAfterFailedRequest() {

    // given
    Builder builder = createTestObjectFactoryBuilder();
    JestHttpObjectFactory config = spy(builder.build());
    String payload1 = "test1";
    String payload2 = "test2";
    Bulk bulk = createTestBatch(payload1, payload2);
    Function<Bulk, Boolean> failoverHandler = mock(Function.class);
    JestResultHandler<JestResult> resultHandler = config.createResultHandler(bulk, failoverHandler);
    // when
    resultHandler.failed(new IOException());
    // then
    ArgumentCaptor<Bulk> captor = ArgumentCaptor.forClass(Bulk.class);
    verify(failoverHandler, times(1)).apply(captor.capture());
    assertEquals(bulk, captor.getValue());
}