@Test
public void testFlush() throws Exception {

    final Buffer value = Buffer.ascii("TESTDATA");
    codec.write(value);
    final int bytesThatWillBeWritten = value.length();
    expect(writableByteChannel.write(anyObject())).andAnswer(createWriteAnswer(bytesThatWillBeWritten));
    replay(writableByteChannel);
    final BufferState state = codec.flush();
    assertEquals(BufferState.EMPTY, state);
    assertEquals(false, codec.full());
    assertEquals(true, codec.empty());
    assertEquals(bytesThatWillBeWritten, codec.getWriteCounter());
    assertEquals(BufferState.WAS_EMPTY, codec.flush());
}