OptionalUtils { public static <T> Stream<T> stream(Optional<T> value) { return value.map(Stream::of).orElseGet(Stream::empty); } private  OptionalUtils(); @SuppressWarnings("unchecked") static Optional<T> or(Optional<T> value, Supplier<Optional<? extends T>> supplier); static Stream<T> stream(Optional<T> value); static void ifPresentOrElse(Optional<T> value, Consumer<T> action, Runnable emptyAction);  }
@Test public void streamUsesValue() { assertThat(OptionalUtils.stream(Optional.of("Kevin")).count(), equalTo(1L)); }
@Test public void streamIsEmpty() { assertThat(OptionalUtils.stream(Optional.empty()).count(), equalTo(0L)); }