ResultIterator implements Iterator<T> { public static <T> Iterator<T> create(long offset, long max, Iterator<T> iterator) { if (offset == OFFSET_NONE && max == MAX_ALL) { return iterator; } else { return new ResultIterator<>(offset, max, iterator); } } private  ResultIterator(long offset, long max, Iterator<T> iterator); static Iterator<T> create(long offset, long max, Iterator<T> iterator); @Override boolean hasNext(); @Override T next(); @Override void remove(); static final int OFFSET_NONE; static final int MAX_ALL; }
@Test(expected = IllegalArgumentException.class) public void createWithNegativeOffset() { ResultIterator.create(-1, ResultIterator.MAX_ALL, Collections.emptyIterator()); }
@Test public void testCreateWithoutLimitation() { Iterator<String> it = ImmutableList.of("str").iterator(); assertSame(it, ResultIterator.create(ResultIterator.OFFSET_NONE, ResultIterator.MAX_ALL, it)); }
@Test public void testCreateOffsetLtSize() { assertEquals(1, Iterators.size(ResultIterator.create(1, ResultIterator.MAX_ALL, ImmutableList.of("str", "str").iterator()))); }
@Test public void testCreateOffsetEqualsMax() { assertEquals(1, Iterators.size(ResultIterator.create(1, 1, ImmutableList.of("str", "str").iterator()))); }
@Test public void testCreateOffsetGtMax() { assertEquals(1, Iterators.size(ResultIterator.create(2, 1, ImmutableList.of("str", "str", "str").iterator()))); }
@Test public void testCreateOffsetLtMax() { Iterator resultIt = ResultIterator.create(1, 3, ImmutableList.of("str", "str", "str", "str").iterator()); assertEquals(3, Iterators.size(resultIt)); }