@Test
public void testCompare() {

    List<ByteBuf> expected = new ArrayList<ByteBuf>();
    expected.add(wrappedBuffer(new byte[]{1}));
    expected.add(wrappedBuffer(new byte[]{1, 2}));
    expected.add(wrappedBuffer(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}));
    expected.add(wrappedBuffer(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}));
    expected.add(wrappedBuffer(new byte[]{2}));
    expected.add(wrappedBuffer(new byte[]{2, 3}));
    expected.add(wrappedBuffer(new byte[]{2, 3, 4, 5, 6, 7, 8, 9, 10, 11}));
    expected.add(wrappedBuffer(new byte[]{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}));
    expected.add(wrappedBuffer(new byte[]{2, 3, 4}, 1, 1));
    expected.add(wrappedBuffer(new byte[]{1, 2, 3, 4}, 2, 2));
    expected.add(wrappedBuffer(new byte[]{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 1, 10));
    expected.add(wrappedBuffer(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 2, 12));
    expected.add(wrappedBuffer(new byte[]{2, 3, 4, 5}, 2, 1));
    expected.add(wrappedBuffer(new byte[]{1, 2, 3, 4, 5}, 3, 2));
    expected.add(wrappedBuffer(new byte[]{2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 2, 10));
    expected.add(wrappedBuffer(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, 3, 12));
    for (int i = 0; i < expected.size(); i ++) {
        for (int j = 0; j < expected.size(); j ++) {
            if (i == j) {
                assertEquals(0, ByteBufUtil.compare(expected.get(i), expected.get(j)));
            } else if (i < j) {
                assertTrue(ByteBufUtil.compare(expected.get(i), expected.get(j)) < 0);
            } else {
                assertTrue(ByteBufUtil.compare(expected.get(i), expected.get(j)) > 0);
            }
        }
    }
    for (ByteBuf buffer: expected) {
        buffer.release();
    }
}