StreamUtils { public static <T> Stream<T> flatten(Collection<Stream<T>> streams) { return flatten(streams.stream()); }  @SafeVarargs static Stream<T> ofNullables(T... array); static Stream<T> ofNullable(T[] array); static Stream<T> ofOptional(Optional<T[]> array); static Stream<T> flatten(Collection<Stream<T>> streams); static Stream<T> flatten(Stream<Stream<T>> streams); @SafeVarargs static Stream<T> flatten(Stream<T>... streams); static Stream<T> unfold(T seed, Function<T, Optional<T>> generator); static Stream<T> iterate(T seed, Long limit, Function<T, Stream<T>> generator);  }
@Test void flattenShouldReturnEmptyWhenEmptyStreams() { assertThat( StreamUtils.<Integer>flatten(ImmutableList.of()) .collect(Guavate.toImmutableList())) .isEmpty(); }
@Test void flattenShouldPreserveSingleStreams() { assertThat( StreamUtils.flatten(ImmutableList.of( Stream.of(1, 2, 3))) .collect(Guavate.toImmutableList())) .containsExactly(1, 2, 3); }
@Test void flattenShouldMergeSeveralStreamsTogether() { assertThat( StreamUtils.flatten(ImmutableList.of( Stream.of(1, 2, 3), Stream.of(4, 5))) .collect(Guavate.toImmutableList())) .containsExactly(1, 2, 3, 4, 5); }
@Test void flattenShouldAcceptEmptyStreams() { assertThat( StreamUtils.flatten(ImmutableList.of( Stream.of())) .collect(Guavate.toImmutableList())) .isEmpty(); }
@Test void flattenShouldMergeEmptyStreamsWithOtherData() { assertThat( StreamUtils.flatten(ImmutableList.of( Stream.of(1, 2), Stream.of(), Stream.of(3))) .collect(Guavate.toImmutableList())) .containsExactly(1, 2, 3); }
@Test void flattenShouldAcceptEmptyVarArg() { assertThat( StreamUtils.flatten() .collect(Guavate.toImmutableList())) .isEmpty(); }
@Test void flattenShouldThrowOnNullVarArg() { Stream<String>[] streams = null; assertThatThrownBy(() -> StreamUtils.flatten(streams).collect(Guavate.toImmutableList())) .isInstanceOf(NullPointerException.class); }
@Test void flattenShouldFlattenNonEmptyVarArg() { assertThat(StreamUtils.flatten(Stream.of(1), Stream.of(2)).collect(Guavate.toImmutableList())) .containsExactly(1, 2); }