@Test public void itThrowsTheCorrectExceptionWhenUnwrapping() throws Exception { assertThatExceptionOfType(SampleErrorException.class) .isThrownBy(() -> ERR_RESULT.unwrapOrElseThrow(SampleErrorException::new)) .withMessage(SampleError.TEST_ERROR.name()); }
public <X extends Throwable> SUCCESS_TYPE unwrapOrElseThrow(Supplier<? extends X> exceptionSupplier) throws X { return Results.getOk(this) .orElseThrow(exceptionSupplier); }
Result { public <X extends Throwable> SUCCESS_TYPE unwrapOrElseThrow(Supplier<? extends X> exceptionSupplier) throws X { return Results.getOk(this) .orElseThrow(exceptionSupplier); } }
Result { public <X extends Throwable> SUCCESS_TYPE unwrapOrElseThrow(Supplier<? extends X> exceptionSupplier) throws X { return Results.getOk(this) .orElseThrow(exceptionSupplier); } Result(); }
Result { public <X extends Throwable> SUCCESS_TYPE unwrapOrElseThrow(Supplier<? extends X> exceptionSupplier) throws X { return Results.getOk(this) .orElseThrow(exceptionSupplier); } Result(); static Result<SUCCESS_TYPE, E> ok(SUCCESS_TYPE success); static Result<T, ERROR_TYPE> err(ERROR_TYPE error); static Result<NullValue, ERROR_TYPE> nullOk(); static Result<SUCCESS_TYPE, NullValue> nullErr(); boolean isOk(); void ifOk(Consumer<? super SUCCESS_TYPE> consumer); boolean isErr(); void ifErr(Consumer<? super ERROR_TYPE> consumer); Result<SUCCESS_TYPE, NEW_ERROR_TYPE> mapErr(Function<ERROR_TYPE, NEW_ERROR_TYPE> mapper); Result<NEW_SUCCESS_TYPE, ERROR_TYPE> mapOk(Function<SUCCESS_TYPE, NEW_SUCCESS_TYPE> mapper); Result<NEW_SUCCESS_TYPE, ERROR_TYPE> flatMapOk(Function<SUCCESS_TYPE, Result<NEW_SUCCESS_TYPE, ERROR_TYPE>> mapper); Result<SUCCESS_TYPE, NEW_ERROR_TYPE> flatMapErr(Function<ERROR_TYPE, Result<SUCCESS_TYPE, NEW_ERROR_TYPE>> mapper); SUCCESS_TYPE unwrapOrElseThrow(Supplier<? extends X> exceptionSupplier); SUCCESS_TYPE unwrapOrElseThrow(Function<ERROR_TYPE, ? extends X> exceptionMapper); SUCCESS_TYPE unwrapOrElseThrow(); SUCCESS_TYPE expect(String message); ERROR_TYPE unwrapErrOrElseThrow(Supplier<? extends X> exceptionSupplier); ERROR_TYPE unwrapErrOrElseThrow(Function<SUCCESS_TYPE, ? extends X> exceptionMapper); ERROR_TYPE unwrapErrOrElseThrow(); ERROR_TYPE expectErr(String message); abstract R match(Function<ERROR_TYPE, R> err, Function<SUCCESS_TYPE, R> ok); @Override abstract int hashCode(); @Override abstract boolean equals(Object obj); @Override String toString(); }
Result { public <X extends Throwable> SUCCESS_TYPE unwrapOrElseThrow(Supplier<? extends X> exceptionSupplier) throws X { return Results.getOk(this) .orElseThrow(exceptionSupplier); } Result(); static Result<SUCCESS_TYPE, E> ok(SUCCESS_TYPE success); static Result<T, ERROR_TYPE> err(ERROR_TYPE error); static Result<NullValue, ERROR_TYPE> nullOk(); static Result<SUCCESS_TYPE, NullValue> nullErr(); boolean isOk(); void ifOk(Consumer<? super SUCCESS_TYPE> consumer); boolean isErr(); void ifErr(Consumer<? super ERROR_TYPE> consumer); Result<SUCCESS_TYPE, NEW_ERROR_TYPE> mapErr(Function<ERROR_TYPE, NEW_ERROR_TYPE> mapper); Result<NEW_SUCCESS_TYPE, ERROR_TYPE> mapOk(Function<SUCCESS_TYPE, NEW_SUCCESS_TYPE> mapper); Result<NEW_SUCCESS_TYPE, ERROR_TYPE> flatMapOk(Function<SUCCESS_TYPE, Result<NEW_SUCCESS_TYPE, ERROR_TYPE>> mapper); Result<SUCCESS_TYPE, NEW_ERROR_TYPE> flatMapErr(Function<ERROR_TYPE, Result<SUCCESS_TYPE, NEW_ERROR_TYPE>> mapper); SUCCESS_TYPE unwrapOrElseThrow(Supplier<? extends X> exceptionSupplier); SUCCESS_TYPE unwrapOrElseThrow(Function<ERROR_TYPE, ? extends X> exceptionMapper); SUCCESS_TYPE unwrapOrElseThrow(); SUCCESS_TYPE expect(String message); ERROR_TYPE unwrapErrOrElseThrow(Supplier<? extends X> exceptionSupplier); ERROR_TYPE unwrapErrOrElseThrow(Function<SUCCESS_TYPE, ? extends X> exceptionMapper); ERROR_TYPE unwrapErrOrElseThrow(); ERROR_TYPE expectErr(String message); abstract R match(Function<ERROR_TYPE, R> err, Function<SUCCESS_TYPE, R> ok); @Override abstract int hashCode(); @Override abstract boolean equals(Object obj); @Override String toString();  }