### Question:
SingletonStream implements Stream<T> { @Override public T reduce(T identity, BinaryOperator<T> accumulator) { checkConsumed(); requireNonNull(accumulator); return accumulator.apply(identity, element); } private  SingletonStream(T element); static SingletonStream<T> of(T element); static Stream<T> ofNullable(T element); @Override Stream<T> filter(Predicate<? super T> predicate); @Override Stream<R> map(Function<? super T, ? extends R> mapper); @Override IntStream mapToInt(ToIntFunction<? super T> mapper); @Override LongStream mapToLong(ToLongFunction<? super T> mapper); @Override DoubleStream mapToDouble(ToDoubleFunction<? super T> mapper); @Override Stream<R> flatMap(Function<? super T, ? extends Stream<? extends R>> mapper); @Override IntStream flatMapToInt(Function<? super T, ? extends IntStream> mapper); @Override LongStream flatMapToLong(Function<? super T, ? extends LongStream> mapper); @Override DoubleStream flatMapToDouble(Function<? super T, ? extends DoubleStream> mapper); @Override SingletonStream<T> distinct(); @Override SingletonStream<T> sorted(); @Override SingletonStream<T> sorted(Comparator<? super T> comparator); @Override Stream<T> peek(Consumer<? super T> action); @Override Stream<T> limit(long maxSize); @Override Stream<T> skip(long n); @Override void forEach(Consumer<? super T> action); @Override void forEachOrdered(Consumer<? super T> action); @Override Object[] toArray(); @SuppressWarnings("unchecked") @Override A[] toArray(IntFunction<A[]> generator); @Override T reduce(T identity, BinaryOperator<T> accumulator); @Override Optional<T> reduce(BinaryOperator<T> accumulator); @Override U reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner); @Override R collect(Supplier<R> supplier, BiConsumer<R, ? super T> accumulator, BiConsumer<R, R> combiner); @Override R collect(Collector<? super T, A, R> collector); @Override Optional<T> min(Comparator<? super T> comparator); @Override Optional<T> max(Comparator<? super T> comparator); @Override long count(); @Override boolean anyMatch(Predicate<? super T> predicate); @Override boolean allMatch(Predicate<? super T> predicate); @Override boolean noneMatch(Predicate<? super T> predicate); @Override Optional<T> findFirst(); @Override Optional<T> findAny(); @Override Iterator<T> iterator(); @Override Spliterator<T> spliterator(); @Override boolean isParallel(); @Override SingletonStream<T> sequential(); @Override Stream<T> parallel(); @Override Stream<T> unordered(); @Override Stream<T> onClose(Runnable closeHandler); @Override void close(); Stream<T> takeWhile(Predicate<? super T> predicate); Stream<T> dropWhile(Predicate<? super T> predicate);  }### Answer:
@Test void reduce() { assertEquals(Optional.of(ELEMENT), instance.reduce((a, b) -> a + b)); assertThrows(IllegalStateException.class, () -> instance.reduce((a, b) -> a + b)); }
@Test void reduce2Arg() { assertEquals(OTHER_ELEMENT + ELEMENT, instance.reduce(OTHER_ELEMENT, (a, b) -> a + b)); assertThrows(IllegalStateException.class, () -> instance.reduce(OTHER_ELEMENT, (a, b) -> a + b)); }
@Test void reduce3Arg() { assertEquals(OTHER_ELEMENT + ELEMENT, instance.reduce(OTHER_ELEMENT, (a, b) -> a + b, (a, b) -> a + b)); assertThrows(IllegalStateException.class, () -> instance.reduce(OTHER_ELEMENT, (a, b) -> a + b, (a, b) -> a + b)); }