@Test
  public void testCompositeWrappedBuffer() {
    ByteBuf header = buffer(12).order(order);
    ByteBuf payload = buffer(512).order(order);

    header.writeBytes(new byte[12]);
    payload.writeBytes(new byte[512]);

    ByteBuf buffer = wrappedBuffer(header, payload);

    assertEquals(12, header.readableBytes());
    assertEquals(512, payload.readableBytes());

    assertEquals(12 + 512, buffer.readableBytes());
    assertEquals(2, buffer.nioBufferCount());
  }
  @Test
  public void testWrittenBuffersEquals() {
    // XXX Same tests than testEquals with written AggregateChannelBuffers
    ByteBuf a, b;
    // Different length.
    a = wrappedBuffer(new byte[] {1}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {1}, new byte[1]).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {2}).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Same content, same firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {1}, new byte[2]).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 2);
    b.writeBytes(wrappedBuffer(new byte[] {2}).order(order));
    b.writeBytes(wrappedBuffer(new byte[] {3}).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Same content, different firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {0, 1, 2, 3, 4}, 1, 3).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {0, 1, 2, 3, 4}, 3, 1).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Different content, same firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = freeLater(wrappedBuffer(wrappedBuffer(new byte[] {1, 2}, new byte[1]).order(order)));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {4}).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Different content, different firstIndex, short length.
    a = wrappedBuffer(new byte[] {1, 2, 3}).order(order);
    b = wrappedBuffer(wrappedBuffer(new byte[] {0, 1, 2, 4, 5}, 1, 3).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 1);
    b.writeBytes(wrappedBuffer(new byte[] {0, 1, 2, 4, 5}, 3, 1).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Same content, same firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b = freeLater(wrappedBuffer(wrappedBuffer(new byte[] {1, 2, 3}, new byte[7])).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 7);
    b.writeBytes(wrappedBuffer(new byte[] {4, 5, 6}).order(order));
    b.writeBytes(wrappedBuffer(new byte[] {7, 8, 9, 10}).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Same content, different firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b =
        wrappedBuffer(
            wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 1, 10).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 5);
    b.writeBytes(
        wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 6, 5).order(order));
    assertTrue(ByteBufUtil.equals(a, b));

    // Different content, same firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b =
        freeLater(
            wrappedBuffer(wrappedBuffer(new byte[] {1, 2, 3, 4, 6}, new byte[5])).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 5);
    b.writeBytes(wrappedBuffer(new byte[] {7, 8, 5, 9, 10}).order(order));
    assertFalse(ByteBufUtil.equals(a, b));

    // Different content, different firstIndex, long length.
    a = wrappedBuffer(new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).order(order);
    b =
        wrappedBuffer(
            wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11}, 1, 10).order(order));
    // to enable writeBytes
    b.writerIndex(b.writerIndex() - 5);
    b.writeBytes(
        wrappedBuffer(new byte[] {0, 1, 2, 3, 4, 6, 7, 8, 5, 9, 10, 11}, 6, 5).order(order));
    assertFalse(ByteBufUtil.equals(a, b));
  }