@Test
public void prepareRequestCreatesRequestWithSerializedBulk() throws IOException {

    // given
    ItemSource<ByteBuf> payload1 = createDefaultTestItemSource("test1");
    ItemSource<ByteBuf> payload2 = createDefaultTestItemSource("test2");
    BufferedBulk.Builder builder = spy(new BufferedBulk.Builder());
    ByteBufItemSource buffer = new ByteBufItemSource(byteBufAllocator.buffer(32), source -> { });
    builder.withBuffer(buffer);
    Bulk bulk = createTestBatch(builder, payload1, payload2);
    // when
    BufferedJestHttpClient client = createDefaultTestHttpClient();
    HttpUriRequest request = client.prepareRequest((BufferedBulk) bulk);
    // then
    ByteBufInputStream byteBufInputStream = new ByteBufInputStream(buffer.getSource());
    byte[] expectedBody = new byte[byteBufInputStream.available()];
    byteBufInputStream.read(expectedBody);
    byteBufInputStream.reset();
    HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
    ByteBufInputStream content = (ByteBufInputStream) entity.getContent();
    byte[] actualBody = new byte[content.available()];
    content.read(actualBody);
    Assert.assertEquals(new String(expectedBody), new String(actualBody));
}