### Question:
HCFailedItemOps implements FailedItemOps<IndexRequest> { @Override public FailedItemSource createItem(IndexRequest failed) { if (failed.getSource() instanceof FailedItemSource) { LOG.trace("Reusing {}", FailedItemSource.class.getSimpleName()); return (FailedItemSource) failed.getSource(); } return new FailedItemSource<>(failed.getSource(), createInfo(failed)); }  @Override FailedItemSource createItem(IndexRequest failed); @Override FailedItemInfo createInfo(IndexRequest failed);  }### Answer:
@Test public void createsFailedItemSourceFromGivenRequest() { HCFailedItemOps failedItemOps = new HCFailedItemOps(); ItemSource<ByteBuf> itemSource = mock(ItemSource.class); ByteBuf expectedSource = mock(ByteBuf.class); when(itemSource.getSource()).thenReturn(expectedSource); String expectedIndex = UUID.randomUUID().toString(); IndexRequest request = createDefaultTestIndexRequest(itemSource, expectedIndex); FailedItemSource result = failedItemOps.createItem(request); assertEquals(expectedSource, result.getSource()); assertEquals(expectedIndex, result.getInfo().getTargetName()); }
@Test public void canReuseFailedItemSourceFromGivenRequest() { HCFailedItemOps failedItemOps = new HCFailedItemOps(); FailedItemSource<ByteBuf> itemSource = mock(FailedItemSource.class); IndexRequest request = createDefaultTestIndexRequest( itemSource, UUID.randomUUID().toString() ); FailedItemSource result = failedItemOps.createItem(request); assertSame(itemSource, result); }