/** * {@inheritDoc} */ @Override public char charAt(int index) { if ((index < 0) || (index >= length)) { throw new IllegalArgumentException("Index out of bounds (" + index + ")"); } return CharacterRingBuffer.this.charAt(index + offset); }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void testOutOfBoundsIndex() { CharacterRingBuffer rb = new CharacterRingBuffer("test"); rb.charAt(4); } }
@Test(expectedExceptions = { IllegalArgumentException.class }) public void testNegativeIndex() { CharacterRingBuffer rb = new CharacterRingBuffer("test"); rb.charAt(-1); }
@Test public void testSimple() { CharacterRingBuffer rb = new CharacterRingBuffer("abcdefg"); for (int pos = 0; pos < "abcdefg".length(); pos++) { assertThat(rb.charAt(pos), equalTo("abcdefg".charAt(pos))); } }
@Test public void testWithWrapping() { CharacterRingBuffer rb = new CharacterRingBuffer(10); rb.append("123456789"); rb.erase(5); rb.append("abcd"); for (int pos = 0; pos < "6789abcd".length(); pos++) { assertThat(rb.charAt(pos), equalTo("6789abcd".charAt(pos))); } }