@ParameterizedTest @ArgumentsSource(TestCaseArgumentsProvider.class) @TestCase({"null", "empty"}) @TestCase({"", "empty"}) @TestCase({"Some Value", "Some Value"}) void ofOnly(List<String> input, Optional<String> expected) { Optional<String> result = OptionalUtil.ofOnly(input); assertThat(result, is(expected)); }
public static <T> Optional<T> ofOnly(Iterable<T> iterable) { if (iterable == null) { return Optional.empty(); } return Optional.ofNullable(Iterables.getOnlyElement(iterable, null)); }
OptionalUtil extends UtilityClass { public static <T> Optional<T> ofOnly(Iterable<T> iterable) { if (iterable == null) { return Optional.empty(); } return Optional.ofNullable(Iterables.getOnlyElement(iterable, null)); } }
OptionalUtil extends UtilityClass { public static <T> Optional<T> ofOnly(Iterable<T> iterable) { if (iterable == null) { return Optional.empty(); } return Optional.ofNullable(Iterables.getOnlyElement(iterable, null)); }  }
OptionalUtil extends UtilityClass { public static <T> Optional<T> ofOnly(Iterable<T> iterable) { if (iterable == null) { return Optional.empty(); } return Optional.ofNullable(Iterables.getOnlyElement(iterable, null)); }  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> ofOnly(Iterable<T> iterable) { if (iterable == null) { return Optional.empty(); } return Optional.ofNullable(Iterables.getOnlyElement(iterable, null)); }  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);  }