CircularBuffer { int backwards(final int currentPosition){ if(currentPosition == 0){ return buffer.length-1; }else{ return currentPosition -1; } } CircularBuffer(final int size); void write(final byte data); void readAll(final OutputStream outputStream); void readChunk(final OutputStream outputStream, final int chunkSize); boolean isFull(); boolean isEmpty(); int getAvailableDataLength(); int getBufferSize(); void reset();  }
@Test public void testBackwards() throws Exception { final CircularBuffer buffer = new CircularBuffer(10); assertEquals(9, buffer.backwards(0)); assertEquals(3, buffer.backwards(4)); assertEquals(8, buffer.backwards(9)); }
@Test public void testBackwards_multiplePositions() throws Exception { CircularBuffer buffer = new CircularBuffer(10); assertEquals(4, buffer.backwards(5, 1)); assertEquals(3, buffer.backwards(5, 2)); assertEquals(0, buffer.backwards(5, 5)); assertEquals(9, buffer.backwards(5, 6)); assertEquals(8, buffer.backwards(5, 7)); assertEquals(5, buffer.backwards(5, 10)); assertEquals(4, buffer.backwards(5, 11)); assertEquals(5, buffer.backwards(5, 20)); assertEquals(4, buffer.backwards(5, 21)); }