@Test
void testTrim() {

    // Test trim end.
    final RingBuffer buffer = RingBuffer.fromString("0123456789");
    buffer.removeEnd(3);
    assertThat(buffer.toString()).isEqualTo("0123456");
    buffer.removeEnd(3);
    assertThat(buffer.toString()).isEqualTo("0123");
    buffer.removeEnd(3);
    assertThat(buffer.toString()).isEqualTo("0");
    try {
        buffer.removeEnd(3);
        fail("You can't remove more content than exists");
    } catch (final IndexOutOfBoundsException e) {
        // Ignore.
    }
    assertThat(buffer.toString()).isEqualTo("0");
    buffer.removeEnd(1);
    assertThat(buffer.toString()).isEqualTo("");
    try {
        buffer.removeEnd(-1);
        fail("You can't remove a negative number of characters");
    } catch (final IllegalArgumentException e) {
        // Ignore.
    }
    // Test trim start.
    buffer.append("0123456789");
    buffer.removeStart(3);
    assertThat(buffer.toString()).isEqualTo("3456789");
    buffer.removeStart(3);
    assertThat(buffer.toString()).isEqualTo("6789");
    buffer.removeStart(3);
    assertThat(buffer.toString()).isEqualTo("9");
    try {
        buffer.removeStart(3);
        fail("You can't remove more content than exists");
    } catch (final IndexOutOfBoundsException e) {
        // Ignore.
    }
    assertThat(buffer.toString()).isEqualTo("9");
    buffer.removeStart(1);
    assertThat(buffer.toString()).isEqualTo("");
    try {
        buffer.removeStart(-1);
        fail("You can't remove a negative number of characters");
    } catch (final IllegalArgumentException e) {
        // Ignore.
    }
    // Test space trimming.
    buffer.append("0123456789");
    buffer.trim();
    assertThat(buffer.toString()).isEqualTo("0123456789");
    buffer.append("   ");
    assertThat(buffer.toString()).isEqualTo("3456789   ");
    buffer.trim();
    assertThat(buffer.toString()).isEqualTo("3456789");
    buffer.append("   ");
    assertThat(buffer.toString()).isEqualTo("3456789   ");
    buffer.append(" 0123   ");
    assertThat(buffer.toString()).isEqualTo("   0123   ");
    buffer.trim();
    assertThat(buffer.toString()).isEqualTo("0123");
    buffer.append("   0123   ");
    assertThat(buffer.toString()).isEqualTo("   0123   ");
    buffer.trimStart();
    assertThat(buffer.toString()).isEqualTo("0123   ");
    buffer.append("   0123   ");
    assertThat(buffer.toString()).isEqualTo("   0123   ");
    buffer.trimEnd();
    assertThat(buffer.toString()).isEqualTo("   0123");
}