Iterators { public static <T> Stream<T> toStream(Iterator<T> iterator) { Iterable<T> iterable = () -> iterator; return StreamSupport.stream(iterable.spliterator(), false); }  static Stream<T> toStream(Iterator<T> iterator); static Flux<T> toFlux(Iterator<T> iterator);  }
@Test void toStreamShouldReturnEmptyStreamWhenEmptyIterator() { UnmodifiableIterator<String> emptyIterator = ImmutableList.<String>of().iterator(); Stream<String> actual = Iterators.toStream(emptyIterator); assertThat(actual.count()).isEqualTo(0); }
@Test void toStreamShouldReturnSameContent() { UnmodifiableIterator<String> iterator = ImmutableList.of("a", "b", "c").iterator(); Stream<String> actual = Iterators.toStream(iterator); assertThat(actual.collect(toList())).containsExactly("a", "b", "c"); }