@Test void earlySupplierProducesNonEmpty_findFirst_laterSuppliersNotCalled() throws Exception { @SuppressWarnings("unchecked") Supplier<Optional<String>> notCalled = mock(Supplier.class); when(notCalled.get()).thenReturn(Optional.empty()); Utils.firstPresent(() -> Optional.of("present"), notCalled); verifyZeroInteractions(notCalled); }
@SafeVarargs public static <T> Optional<T> firstPresent(Supplier<Optional<T>>... optionals) { return Arrays.stream(optionals) .map(Supplier::get) .flatMap(Utils::stream) .findFirst(); }
Utils { @SafeVarargs public static <T> Optional<T> firstPresent(Supplier<Optional<T>>... optionals) { return Arrays.stream(optionals) .map(Supplier::get) .flatMap(Utils::stream) .findFirst(); } }
Utils { @SafeVarargs public static <T> Optional<T> firstPresent(Supplier<Optional<T>>... optionals) { return Arrays.stream(optionals) .map(Supplier::get) .flatMap(Utils::stream) .findFirst(); }  }
Utils { @SafeVarargs public static <T> Optional<T> firstPresent(Supplier<Optional<T>>... optionals) { return Arrays.stream(optionals) .map(Supplier::get) .flatMap(Utils::stream) .findFirst(); }  static Stream<T> stream(Optional<T> optional); @SafeVarargs static Optional<T> firstPresent(Supplier<Optional<T>>... optionals); static String toBase64(String content); }
Utils { @SafeVarargs public static <T> Optional<T> firstPresent(Supplier<Optional<T>>... optionals) { return Arrays.stream(optionals) .map(Supplier::get) .flatMap(Utils::stream) .findFirst(); }  static Stream<T> stream(Optional<T> optional); @SafeVarargs static Optional<T> firstPresent(Supplier<Optional<T>>... optionals); static String toBase64(String content);  }