### Question:
Optionals { public static <A, B, R, E extends Throwable> Optional<R> mapBoth( Optional<A> left, Optional<B> right, CheckedBiFunction<? super A, ? super B, ? extends R, E> mapper) throws E { requireNonNull(left); requireNonNull(right); requireNonNull(mapper); if (left.isPresent() && right.isPresent()) { return Optional.ofNullable(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 map_leftIsEmpty() { assertThat(mapBoth(Optional.empty(), Optional.of("bar"), action::run)).isEqualTo(Optional.empty()); verify(action, never()).run(any(), any()); }
@Test public void map_rightIsEmpty() { assertThat(mapBoth(Optional.of("foo"), Optional.empty(), action::run)).isEqualTo(Optional.empty()); verify(action, never()).run(any(), any()); }
@Test public void map_bothArePresent_mapperReturnsNull() { assertThat(mapBoth(Optional.of("foo"), Optional.empty(), (a, b) -> null)) .isEqualTo(Optional.empty()); }
@Test public void map_bothArePresent_mapperReturnsNonNull() { assertThat(mapBoth(Optional.of("foo"), Optional.of("bar"), (a, b) -> a + b)) .isEqualTo(Optional.of("foobar")); }