throw exceptionMapper.apply(second());
}
- /**
- * Return contained value if present or throw the exception supplied by supplier.
- *
- * @param supplier Exception supplier
- * @param <X> Thrown exception type
- * @return Contained value
- * @throws NullPointerException if {@code exceptionMapper} is null
- * @throws X When there is no contained value
- * @deprecated This method is losing the underlying failure cause. Use {@link #orElseThrow(Function)} instead.
- */
- @Deprecated(forRemoval = true, since = "8.0.2")
- public final <X extends Throwable> T orElseThrow(final Supplier<X> supplier) throws X {
- requireNonNull(supplier);
- if (isFirst()) {
- return first();
- }
- throw supplier.get();
- }
-
/**
* Complete target {@link CompletableFuture} either successfully or exceptionally based on the state of this object.
*
verifyNoInteractions(mapper);
}
- @Test
- public void testOrElseThrow() {
- final String foo = "foo";
- assertSame(foo, CheckedValue.ofValue(foo)
- .orElseThrow((Supplier<NullPointerException>)NullPointerException::new));
- }
-
- @Test
- public void testThrowableOrElseThrow() {
- final CheckedValue<?, ?> value = CheckedValue.ofException(new NullPointerException("foo"));
- final Exception mock = mock(Exception.class);
- assertThrows(mock.getClass(), () -> value.orElseThrow(() -> mock));
- }
-
@Test
public void testOrElseGet() {
final String foo = "foo";