MarkableIterator implements Iterator<T> { public void reset() { if (state == State.READ) { throw new IllegalStateException("Iterator has not been marked or the mark has been invalidated"); } replayIterator = replayBuffer.iterator(); state = State.REPLAY; } MarkableIterator(Iterator<T> backingIterator); @Override boolean hasNext(); @Override T next(); @Override void remove(); void mark(int readLimit); void reset();  }
@Test(expected = IllegalStateException.class) public void testResetWithoutMark() { List<Integer> input = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); MarkableIterator<Integer> markableIterator= new MarkableIterator<Integer>(input.iterator()); Assert.assertEquals(MarkableIterator.State.READ, markableIterator.state); markableIterator.reset(); }