    @Test
    public void toByteArray() throws ReflectiveOperationException {

        final byte[] expected = new byte[] {0, 1, 2, 3, 4, 5};
        assertToByteArray("Wrap", expected, ByteBuffer.wrap(expected));
        assertToByteArray("Wrap-RO", expected, ByteBuffer.wrap(expected).asReadOnlyBuffer());

        assertToByteArray("Wrap-Truncated-Sliced", expected, ByteBuffer.wrap(new byte[] {0, 1, 2, 3, 4, 5, 6}, 0, 6).slice());
        assertToByteArray("Wrap-Offset-Sliced", expected, ByteBuffer.wrap(new byte[] {6, 0, 1, 2, 3, 4, 5, 6}, 1, 6).slice());
        assertToByteArray("Wrap-Truncated", expected, ByteBuffer.wrap(new byte[] {0, 1, 2, 3, 4, 5, 6}, 0, 6));
        assertToByteArray("Wrap-Offset", expected, ByteBuffer.wrap(new byte[] {6, 0, 1, 2, 3, 4, 5, 6}, 1, 6));

        ByteBuffer buff = ByteBuffer.allocate(expected.length + 10);
        buff.put(expected);
        buff.flip();
        assertToByteArray("Normal", expected, buff);

        buff = ByteBuffer.allocateDirect(expected.length + 10);
        buff.put(expected);
        buff.flip();
        assertToByteArray("Direct", expected, buff);
    }