@Test public void next_ThrowsExceptionWithEmptyList() { PeekIterator<Integer> tested = new PeekIterator<Integer>( emptyList.iterator()); boolean thrown = false; try { tested.next(); } catch (NoSuchElementException e) { thrown = true; } assertTrue(String.format("Exception: %s not thrown", NoSuchElementException.class.getCanonicalName()), thrown); }
@Override public T next() { if (!hasNext()) { throw (new NoSuchElementException("Iterator has no elements left.")); } T toReturn = nextitem; nextitem = null; return toReturn; }
PeekIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw (new NoSuchElementException("Iterator has no elements left.")); } T toReturn = nextitem; nextitem = null; return toReturn; } }
PeekIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw (new NoSuchElementException("Iterator has no elements left.")); } T toReturn = nextitem; nextitem = null; return toReturn; } PeekIterator(Iterator<T> iterator); }
PeekIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw (new NoSuchElementException("Iterator has no elements left.")); } T toReturn = nextitem; nextitem = null; return toReturn; } PeekIterator(Iterator<T> iterator); @Override boolean hasNext(); @Override T next(); T peek(); @Override void remove(); }
PeekIterator implements Iterator<T> { @Override public T next() { if (!hasNext()) { throw (new NoSuchElementException("Iterator has no elements left.")); } T toReturn = nextitem; nextitem = null; return toReturn; } PeekIterator(Iterator<T> iterator); @Override boolean hasNext(); @Override T next(); T peek(); @Override void remove();  }