### Question:
Optionals { public static <A, B, R, E extends Throwable> Optional<R> flatMapBoth( Optional<A> left, Optional<B> right, CheckedBiFunction<? super A, ? super B, ? extends Optional<R>, E> mapper) throws E { requireNonNull(left); requireNonNull(right); requireNonNull(mapper); if (left.isPresent() && right.isPresent()) { return requireNonNull(mapper.apply(left.get(), right.get())); } return Optional.empty(); } private  Optionals(); static Optional<T> optionally(
      boolean condition, CheckedSupplier<? extends T, E> supplier); static Optional<T> optional(boolean condition, T value); static Premise ifPresent(
      OptionalInt optional, CheckedIntConsumer<E> consumer); static Premise ifPresent(
      OptionalLong optional, CheckedLongConsumer<E> consumer); static Premise ifPresent(
      OptionalDouble optional, CheckedDoubleConsumer<E> consumer); static Premise ifPresent(
      Optional<T> optional, CheckedConsumer<? super T, E> consumer); static Premise ifPresent(
      Optional<A> left, Optional<B> right, CheckedBiConsumer<? super A, ? super B, E> consumer); static Optional<R> mapBoth(
      Optional<A> left, Optional<B> right, CheckedBiFunction<? super A, ? super B, ? extends R, E> mapper); static Optional<R> flatMapBoth(
      Optional<A> left, Optional<B> right,
      CheckedBiFunction<? super A, ? super B, ? extends Optional<R>, E> mapper);  }### Answer:
@Test public void flatMap_leftIsEmpty() { assertThat(flatMapBoth( Optional.empty(), Optional.of("bar"),(a, b) -> Optional.of(action.run(a, b)))) .isEqualTo(Optional.empty()); verify(action, never()).run(any(), any()); }
@Test public void flatMap_rightIsEmpty() { assertThat(flatMapBoth( Optional.of("foo"), Optional.empty(),(a, b) -> Optional.of(action.run(a, b)))) .isEqualTo(Optional.empty()); verify(action, never()).run(any(), any()); }
@Test public void flatMap_bothPresent_mapperReturnsNull() { assertThrows( NullPointerException.class, () -> flatMapBoth(Optional.of("foo"), Optional.of("bar"), (a, b) -> null)); }
@Test public void flatMap_bothPresent_mapperReturnsNonNull() { assertThat(flatMapBoth(Optional.of("foo"), Optional.of("bar"), (a, b) -> Optional.of(a + b))) .isEqualTo(Optional.of("foobar")); }