@Test
public void testDecodingWithSmallBuffer() throws Exception {

    final String s1 = "5\r\n01234\r\n5\r\n5678";
    final String s2 = "9\r\n6\r\nabcdef\r\n0\r\n\r\n";
    final ReadableByteChannel channel = new ReadableByteChannelMock(
            new String[] {s1, s2}, StandardCharsets.US_ASCII);
    final SessionInputBuffer inbuf = new SessionInputBufferImpl(1024, 256, 0, StandardCharsets.US_ASCII);
    final BasicHttpTransportMetrics metrics = new BasicHttpTransportMetrics();
    final ChunkDecoder decoder = new ChunkDecoder(channel, inbuf, metrics);
    final ByteBuffer dst = ByteBuffer.allocate(1024);
    final ByteBuffer tmp = ByteBuffer.allocate(4);
    int bytesRead = 0;
    while (dst.hasRemaining() && !decoder.isCompleted()) {
        final int i = decoder.read(tmp);
        if (i > 0) {
            bytesRead += i;
        }
        tmp.flip();
        dst.put(tmp);
        tmp.compact();
    }
    Assert.assertEquals(16, bytesRead);
    Assert.assertEquals("0123456789abcdef", CodecTestUtils.convert(dst));
    Assert.assertTrue(decoder.isCompleted());
    dst.clear();
    bytesRead = decoder.read(dst);
    Assert.assertEquals(-1, bytesRead);
    Assert.assertTrue(decoder.isCompleted());
}