@Test
void testLength() {

    final RingBuffer buffer = RingBuffer.fromString("0123456789");
    assertThat(buffer.length()).isEqualTo(10);
    buffer.setLength(5);
    assertThat(buffer.length()).isEqualTo(5);
    assertThat(buffer.toString()).isEqualTo("01234");
    buffer.append("999");
    assertThat(buffer.length()).isEqualTo(8);
    assertThat(buffer.toString()).isEqualTo("01234999");
    buffer.append("6667");
    assertThat(buffer.length()).isEqualTo(10);
    assertThat(buffer.toString()).isEqualTo("2349996667");
    buffer.setLength(5);
    assertThat(buffer.length()).isEqualTo(5);
    assertThat(buffer.toString()).isEqualTo("23499");
    buffer.setLength(10);
    assertThat(buffer.length()).isEqualTo(10);
    assertThat(buffer.toString()).isEqualTo("2349996667");
    try {
        buffer.setLength(-1);
        fail("You cannot set the length of a buffer less than 0");
    } catch (final IndexOutOfBoundsException e) {
        // Ignore.
    }
    try {
        buffer.setLength(11);
        fail("You cannot set the length of a buffer greater than the buffer size");
    } catch (final IndexOutOfBoundsException e) {
        // Ignore.
    }
}