@Test
public void testProduceDataWithBuffering() throws Exception {

    final AsyncEntityProducer producer = new ChunkCharAsyncEntityProducer(
            256, 5, ContentType.TEXT_PLAIN, "this", " and that", "all", " sorts of stuff");
    final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
    final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
    producer.produce(streamChannel);
    Assert.assertTrue(byteChannel.isOpen());
    Assert.assertEquals("", byteChannel.dump(StandardCharsets.US_ASCII));
    producer.produce(streamChannel);
    Assert.assertTrue(byteChannel.isOpen());
    Assert.assertEquals("this and that", byteChannel.dump(StandardCharsets.US_ASCII));
    producer.produce(streamChannel);
    Assert.assertTrue(byteChannel.isOpen());
    Assert.assertEquals("", byteChannel.dump(StandardCharsets.US_ASCII));
    producer.produce(streamChannel);
    Assert.assertFalse(byteChannel.isOpen());
    Assert.assertEquals("all sorts of stuff", byteChannel.dump(StandardCharsets.US_ASCII));
}