@Test
 public void testRemoveLastComponent() {
   CompositeByteBuf buf = freeLater(compositeBuffer());
   buf.addComponent(wrappedBuffer(new byte[] {1, 2}));
   assertEquals(1, buf.numComponents());
   buf.removeComponent(0);
   assertEquals(0, buf.numComponents());
 }
  @Test
  public void testAutoConsolidation() {
    CompositeByteBuf buf = compositeBuffer(2);

    buf.addComponent(wrappedBuffer(new byte[] {1}));
    assertEquals(1, buf.numComponents());

    buf.addComponent(wrappedBuffer(new byte[] {2, 3}));
    assertEquals(2, buf.numComponents());

    buf.addComponent(wrappedBuffer(new byte[] {4, 5, 6}));

    assertEquals(1, buf.numComponents());
    assertTrue(buf.hasArray());
    assertNotNull(buf.array());
    assertEquals(0, buf.arrayOffset());
  }
  @Test
  public void testFullConsolidation() {
    CompositeByteBuf buf = freeLater(compositeBuffer(Integer.MAX_VALUE));
    buf.addComponent(wrappedBuffer(new byte[] {1}));
    buf.addComponent(wrappedBuffer(new byte[] {2, 3}));
    buf.addComponent(wrappedBuffer(new byte[] {4, 5, 6}));
    buf.consolidate();

    assertEquals(1, buf.numComponents());
    assertTrue(buf.hasArray());
    assertNotNull(buf.array());
    assertEquals(0, buf.arrayOffset());
  }
  @Test
  public void testRangedConsolidation() {
    CompositeByteBuf buf = freeLater(compositeBuffer(Integer.MAX_VALUE));
    buf.addComponent(wrappedBuffer(new byte[] {1}));
    buf.addComponent(wrappedBuffer(new byte[] {2, 3}));
    buf.addComponent(wrappedBuffer(new byte[] {4, 5, 6}));
    buf.addComponent(wrappedBuffer(new byte[] {7, 8, 9, 10}));
    buf.consolidate(1, 2);

    assertEquals(3, buf.numComponents());
    assertEquals(wrappedBuffer(new byte[] {1}), buf.component(0));
    assertEquals(wrappedBuffer(new byte[] {2, 3, 4, 5, 6}), buf.component(1));
    assertEquals(wrappedBuffer(new byte[] {7, 8, 9, 10}), buf.component(2));
  }