AdvanceUntilEmptyIterable extends FluentIterable<FluentIterable<E>> { public FluentIterable<E> concat() { final Iterator<FluentIterable<E>> iterator = iterator(); final UnmodifiableIterator<Iterator<E>> unmodifiable = new UnmodifiableIterator<Iterator<E>>() { @Override public boolean hasNext() { return iterator.hasNext(); } @Override public Iterator<E> next() { return iterator.next().iterator(); } }; return new FluentIterable<E>() { @Override public Iterator<E> iterator() { return Iterators.concat(unmodifiable); } }; } protected  AdvanceUntilEmptyIterable(Supplier<FluentIterable<E>> nextIterable); static AdvanceUntilEmptyIterable<E> create(Supplier<FluentIterable<E>> nextIterable); @Override Iterator<FluentIterable<E>> iterator(); FluentIterable<E> concat();  }
@SuppressWarnings("unchecked") @Test public void testConcatStopsWhenEmpty() { Supplier<FluentIterable<String>> nextIterable = createMock(Supplier.class); expect(nextIterable.get()).andReturn(FluentIterable.from(ImmutableSet.of("foo", "bar"))); expect(nextIterable.get()).andReturn(FluentIterable.from(ImmutableSet.of("boo", "baz"))); expect(nextIterable.get()).andReturn(FluentIterable.from(ImmutableSet.of("ham", "cheeze"))); expect(nextIterable.get()).andReturn(FluentIterable.from(ImmutableSet.<String>of())); EasyMock.replay(nextIterable); AdvanceUntilEmptyIterable<String> iterable = new AdvanceUntilEmptyIterable<String>(nextIterable); Assert.assertEquals(iterable.concat().toSet(), ImmutableSet.of("foo", "bar", "boo", "baz", "ham", "cheeze")); EasyMock.verify(nextIterable); }