@Test
public void canSerializeUniqueItemsSeparately() throws IOException {

    // given
    ObjectWriter writer = spy(new ObjectMapper().writerFor(IndexRequest.class));
    CompositeByteBuf byteBuf1 = createDefaultTestByteBuf();
    ItemSource<ByteBuf> source1 = new ByteBufItemSource(byteBuf1, source -> {});
    String index1 = UUID.randomUUID().toString();
    String mappingType = UUID.randomUUID().toString();
    IndexRequest action1 = createIndexRequestBuilder(source1)
            .index(index1)
            .type(mappingType)
            .build();
    CompositeByteBuf byteBuf2 = createDefaultTestByteBuf();
    ItemSource<ByteBuf> source2 = new ByteBufItemSource(byteBuf2, source -> {});
    String index2 = UUID.randomUUID().toString();
    IndexRequest action2 = createIndexRequestBuilder(source2)
            .index(index2)
            .type(mappingType)
            .build();
    BatchRequest request = new BatchRequest.Builder()
            .withObjectWriter(writer)
            .withBuffer(new ByteBufItemSource(createDefaultTestByteBuf(), source -> {}))
            .add(action1)
            .add(action2)
            .build();
    // when
    request.serialize();
    // then
    ArgumentCaptor<IndexRequest> captor = ArgumentCaptor.forClass(IndexRequest.class);
    verify(writer, times(2)).writeValue((OutputStream)any(), captor.capture());
    List<IndexRequest> allValues = captor.getAllValues();
    assertEquals(2, allValues.size());
    assertEquals(index1, allValues.get(0).getIndex());
    assertEquals(index2, allValues.get(1).getIndex());
    assertEquals(mappingType, allValues.get(0).getType());
    assertEquals(mappingType, allValues.get(1).getType());
}