StreamIterable implements CloseableIterable<T> { @Override public CloseableIterator<T> iterator() { return new StreamIterator<>(streamSupplier.get()); } StreamIterable(final StreamSupplier<T> streamSupplier); @Override void close(); @Override CloseableIterator<T> iterator(); @JsonIgnore Stream<T> getStream();  }
@Test public void shouldDelegateIteratorToIterable() { final StreamSupplier<Object> streamSupplier = mock(StreamSupplier.class); final Stream<Object> stream = mock(Stream.class); given(streamSupplier.get()).willReturn(stream); final StreamIterable<Object> wrappedIterable = new StreamIterable<>(streamSupplier); final Iterator<Object> iterator = mock(Iterator.class); given(stream.iterator()).willReturn(iterator); final CloseableIterator<Object> result = wrappedIterable.iterator(); result.hasNext(); verify(iterator).hasNext(); }