public void testDefaultBehaviorOfPeekForEmptyIteration() { AbstractIterator<Integer> empty = new AbstractIterator<Integer>() { private boolean alreadyCalledEndOfData; @Override public Integer computeNext() { if (alreadyCalledEndOfData) { fail("Should not have been invoked again"); } alreadyCalledEndOfData = true; return endOfData(); } }; try { empty.peek(); fail("peek() should throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { } try { empty.peek(); fail("peek() should continue to throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { } }
assertEquals(0, (int) iter.peek()); assertEquals(0, (int) iter.peek()); assertTrue(iter.hasNext()); assertEquals(0, (int) iter.peek()); assertEquals(0, (int) iter.next()); assertEquals(1, (int) iter.peek()); assertEquals(1, (int) iter.next()); iter.peek(); fail("peek() should throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { iter.peek(); fail("peek() should continue to throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { iter.peek(); fail("peek() should still throw NoSuchElementException after next()"); } catch (NoSuchElementException expected) {
public void testDefaultBehaviorOfPeekForEmptyIteration() { AbstractIterator<Integer> empty = new AbstractIterator<Integer>() { private boolean alreadyCalledEndOfData; @Override public Integer computeNext() { if (alreadyCalledEndOfData) { fail("Should not have been invoked again"); } alreadyCalledEndOfData = true; return endOfData(); } }; try { empty.peek(); fail("peek() should throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { } try { empty.peek(); fail("peek() should continue to throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { } }
assertEquals(0, (int) iter.peek()); assertEquals(0, (int) iter.peek()); assertTrue(iter.hasNext()); assertEquals(0, (int) iter.peek()); assertEquals(0, (int) iter.next()); assertEquals(1, (int) iter.peek()); assertEquals(1, (int) iter.next()); iter.peek(); fail("peek() should throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { iter.peek(); fail("peek() should continue to throw NoSuchElementException at end"); } catch (NoSuchElementException expected) { iter.peek(); fail("peek() should still throw NoSuchElementException after next()"); } catch (NoSuchElementException expected) {