@Test
public void testForEachByte() {

    buffer.clear();
    for (int i = 0; i < CAPACITY; i ++) {
        buffer.writeByte(i + 1);
    }
    final AtomicInteger lastIndex = new AtomicInteger();
    buffer.setIndex(CAPACITY / 4, CAPACITY * 3 / 4);
    assertThat(buffer.forEachByte(new ByteProcessor() {
        int i = CAPACITY / 4;
        @Override
        public boolean process(byte value) throws Exception {
            assertThat(value, is((byte) (i + 1)));
            lastIndex.set(i);
            i ++;
            return true;
        }
    }), is(-1));
    assertThat(lastIndex.get(), is(CAPACITY * 3 / 4 - 1));
}