### Question:
Cases { public static <T> Collector<T, ?, T> onlyElement() { return collectingAndThen(toTinyContainer(), TinyContainer::onlyOne); } private  Cases(); static Collector<T, ?, T> onlyElement(); static Collector<T, ?, R> onlyElements(
      BiFunction<? super T, ? super T, ? extends R> twoElements); static Collector<Object, ?, Optional<R>> when(Supplier<? extends R> noElement); static Collector<T, ?, Optional<R>> when(Function<? super T, ? extends R> onlyOne); static Collector<T, ?, Optional<R>> when(
      Predicate<? super T> condition, Function<? super T, ? extends R> onlyOne); static Collector<T, ?, Optional<R>> when(
      BiFunction<? super T, ? super T, ? extends R> onlyTwo); static Collector<T, ?, Optional<R>> when(
      BiPredicate<? super T, ? super T> condition,
      BiFunction<? super T, ? super T, ? extends R> onlyTwo); @SafeVarargs static Collector<T, ?, R> switching(
      Collector<? super T, ?, ? extends Optional<? extends R>>... cases);  }### Answer:
@Test public void only_oneElement() { String result = Stream.of("foo").collect(onlyElement()); assertThat(result).isEqualTo("foo"); IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> Stream.of(1, 2, 3).collect(onlyElement())); assertThat(thrown).hasMessageThat().contains("size: 3"); }