### Question:
Cases { public static <T, R> Collector<T, ?, R> onlyElements( BiFunction<? super T, ? super T, ? extends R> twoElements) { requireNonNull(twoElements); return collectingAndThen(toTinyContainer(), c -> c.only(twoElements)); } 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_twoElements() { int result = Stream.of(2, 3).collect(onlyElements((a, b) -> a * b)); assertThat(result).isEqualTo(6); IllegalArgumentException thrown = assertThrows( IllegalArgumentException.class, () -> Stream.of(1).collect(onlyElements((a, b) -> a * b))); assertThat(thrown).hasMessageThat().contains("size: 1"); }