@ParameterizedTest @ArgumentsSource(TestCaseArgumentsProvider.class) @TestCase({"empty", "empty", "empty", "1"}) @TestCase({"123", "empty", "123", "0"}) @TestCase({"empty", "234", "234", "1"}) @TestCase({"123", "234", "123", "0"}) void orGet(Optional<Integer> a, Optional<Integer> b, Optional<Integer> expected, int expectedGets) { if (expectedGets > 0) { when(supplier.get()).thenReturn(b); } Optional<Integer> result = OptionalUtil.orGet(a, supplier); assertThat(result, is(expected)); verify(supplier, times(expectedGets)).get(); }
public static <T> Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier) { return optional.isPresent() ? optional : supplier.get().map(Function.identity()); }
OptionalUtil extends UtilityClass { public static <T> Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier) { return optional.isPresent() ? optional : supplier.get().map(Function.identity()); } }
OptionalUtil extends UtilityClass { public static <T> Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier) { return optional.isPresent() ? optional : supplier.get().map(Function.identity()); }  }
OptionalUtil extends UtilityClass { public static <T> Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier) { return optional.isPresent() ? optional : supplier.get().map(Function.identity()); }  static Optional<T> ofBlankable(T s); static Optional<T> ofOnly(Iterable<T> iterable); static OptionalWrapper<T> with(Optional<T> optional); static Optional<T> or(Optional<T> optional, Optional<T> other); static Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier); static Optional<U> as(Class<U> targetClass, Optional<T> source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, Optional<T> source); static Optional<U> as(Class<U> targetClass, T source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, T source); }
OptionalUtil extends UtilityClass { public static <T> Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier) { return optional.isPresent() ? optional : supplier.get().map(Function.identity()); }  static Optional<T> ofBlankable(T s); static Optional<T> ofOnly(Iterable<T> iterable); static OptionalWrapper<T> with(Optional<T> optional); static Optional<T> or(Optional<T> optional, Optional<T> other); static Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier); static Optional<U> as(Class<U> targetClass, Optional<T> source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, Optional<T> source); static Optional<U> as(Class<U> targetClass, T source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, T source);  }