### Question:
AbstractIterator2 implements Iterator<E> { @Override public E next() { if (finished) { throw new NoSuchElementException("No (more) elements"); } if (!ready) { next = getNext(); if (finished) { throw new NoSuchElementException("No (more) elements"); } } ready = false; return next; }  @Override boolean hasNext(); @Override E next(); @Override final void remove();  }### Answer:
@Test public void throwsOnNextWhenNoMoreElements() { iterator.next(); iterator.next(); iterator.next(); iterator.next(); iterator.next(); try { iterator.next(); Assert.fail("Should throw NoSuchElementException when there are no more elements"); } catch (NoSuchElementException e) { } }
@Test public void allowsIteratingWithNext() { assertEquals(0, (int) iterator.next()); assertEquals(1, (int) iterator.next()); assertEquals(2, (int) iterator.next()); assertEquals(3, (int) iterator.next()); assertEquals(4, (int) iterator.next()); }