@Test public void testMakeNextReturnsNull() { final Iterator<Object> iter = new AbstractIterator<Object>() { @Nullable @Override protected Object makeNext() { return null; } }; assertThat(iter.hasNext()).isTrue(); assertThatThrownBy(iter::next) .isInstanceOf(IllegalStateException.class) .hasMessage("expected item but none found"); }
@Override public boolean hasNext() { switch (state) { case FAILED: throw new IllegalStateException("iterator is in failed state"); case DONE: return false; case READY: return true; default: return maybeComputeNext(); } }
AbstractIterator implements Iterator<T> { @Override public boolean hasNext() { switch (state) { case FAILED: throw new IllegalStateException("iterator is in failed state"); case DONE: return false; case READY: return true; default: return maybeComputeNext(); } } }
AbstractIterator implements Iterator<T> { @Override public boolean hasNext() { switch (state) { case FAILED: throw new IllegalStateException("iterator is in failed state"); case DONE: return false; case READY: return true; default: return maybeComputeNext(); } }  }
AbstractIterator implements Iterator<T> { @Override public boolean hasNext() { switch (state) { case FAILED: throw new IllegalStateException("iterator is in failed state"); case DONE: return false; case READY: return true; default: return maybeComputeNext(); } }  @Override boolean hasNext(); @Override T next(); @Override void remove(); T peek(); }
AbstractIterator implements Iterator<T> { @Override public boolean hasNext() { switch (state) { case FAILED: throw new IllegalStateException("iterator is in failed state"); case DONE: return false; case READY: return true; default: return maybeComputeNext(); } }  @Override boolean hasNext(); @Override T next(); @Override void remove(); T peek();  }