PeekIterator implements Iterator<T> { @Override public boolean hasNext() { if (nextitem != null) { return true; } if (iterator.hasNext()) { nextitem = iterator.next(); } return nextitem != null; } PeekIterator(Iterator<T> iterator); @Override boolean hasNext(); @Override T next(); T peek(); @Override void remove();  }
@Test public void hasNext_ReturnsFalseWithEmptyList() { PeekIterator<Integer> tested = new PeekIterator<Integer>( emptyList.iterator()); assertFalse(tested.hasNext()); }
@Test public void hasNext_ReturnsTrueWhenElementsAreLeft() { assertTrue(new PeekIterator<Integer>(listWithElements.iterator()) .hasNext()); }