@Test
void testEnsureCapacity() {

    ByteBuffer b = BufferUtils.toBuffer("Goodbye Cruel World");
    assertSame(b, BufferUtils.ensureCapacity(b, 0));
    assertSame(b, BufferUtils.ensureCapacity(b, 10));
    assertSame(b, BufferUtils.ensureCapacity(b, b.capacity()));
    ByteBuffer b1 = BufferUtils.ensureCapacity(b, 64);
    assertNotSame(b, b1);
    assertEquals(64, b1.capacity());
    assertEquals("Goodbye Cruel World", BufferUtils.toString(b1));
    b1.position(8);
    b1.limit(13);
    assertEquals("Cruel", BufferUtils.toString(b1));
    ByteBuffer b2 = b1.slice();
    assertEquals("Cruel", BufferUtils.toString(b2));
    System.err.println(BufferUtils.toDetailString(b2));
    assertEquals(8, b2.arrayOffset());
    assertEquals(5, b2.capacity());
    assertSame(b2, BufferUtils.ensureCapacity(b2, 5));
    ByteBuffer b3 = BufferUtils.ensureCapacity(b2, 64);
    assertNotSame(b2, b3);
    assertEquals(64, b3.capacity());
    assertEquals("Cruel", BufferUtils.toString(b3));
    assertEquals(0, b3.arrayOffset());
    assertEquals(19, b.remaining());
    b.position(19);
    ByteBuffer b4 = BufferUtils.ensureCapacity(b, b.position() + 20);
    BufferUtils.flipToFill(b4);
    b4.position(b.position());
    assertEquals(20, b4.remaining());
    assertEquals(19, b4.position());
    assertEquals(39, b4.capacity());
    BufferUtils.flipToFill(b);
    ByteBuffer b5 = BufferUtils.allocateDirect(19);
    assertEquals(0, b5.remaining());
    assertEquals(19, b.remaining());
    BufferUtils.append(b5, b);
    assertEquals(0, b.remaining());
    assertEquals(19, b5.remaining());
    BufferUtils.flipToFill(b);
    assertEquals(19, b.remaining());
    ByteBuffer b6 = BufferUtils.ensureCapacity(b5, 20);
    assertEquals(19, b6.remaining());
    BufferUtils.flipToFill(b6);
    assertEquals(1, b6.remaining());
}