Assert.assertEquals("header\r\nstuff", s);
}
@Test
public void testCodingFragmentBufferingTinyFragments() throws Exception {
final WritableByteChannelMock channel = Mockito.spy(new WritableByteChannelMock(64));
final SessionOutputBuffer outbuf = Mockito.spy(new SessionOutputBufferImpl(1024, 128));
final HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();
final IdentityEncoder encoder = new IdentityEncoder(channel, outbuf, metrics, 1);
Assert.assertEquals(5, encoder.write(CodecTestUtils.wrap("stuff")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(1, encoder.write(CodecTestUtils.wrap("-")));
Assert.assertEquals(10, encoder.write(CodecTestUtils.wrap("more stuff")));
Mockito.verify(channel, Mockito.times(5)).write(Mockito.<ByteBuffer>any());
Mockito.verify(outbuf, Mockito.times(3)).write(Mockito.<ByteBuffer>any());
Mockito.verify(outbuf, Mockito.times(3)).flush(channel);
Assert.assertEquals(18, metrics.getBytesTransferred());
outbuf.flush(channel);
final String s = channel.dump(Consts.ASCII);
Assert.assertEquals("stuff---more stuff", s);
}