IteratorWithBuffer implements Iterator<T> { public T peek(int idx) { if ( idx < 0 || idx >= capacity ) throw new IndexOutOfBoundsException("Index: " + idx) ; if ( idx >= lookahead.size() ) return null ; return lookahead.get(idx) ; } IteratorWithBuffer(Iterator<T> iter, int N); @Override boolean hasNext(); @Override T next(); @Override void remove(); T peek(int idx); int currentSize(); void set(int idx, T item);  }
@Test public void iterBuffer_03() { IteratorWithBuffer<String> iter = createBuffered(1) ; assertEquals(null, iter.peek(0)) ; }
@Test(expected=IndexOutOfBoundsException.class) public void iterBuffer_04() { IteratorWithBuffer<String> iter = createBuffered(0, "a") ; assertEquals(null, iter.peek(0)) ; }