@Test public void itThrowsWhenExpectErrIsCalledOnOk() throws Exception { String message = "this should throw"; assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(() -> OK_RESULT.expectErr(message)) .withMessage(message); }
public ERROR_TYPE expectErr(String message) { return unwrapErrOrElseThrow(() -> new IllegalStateException(message)); }
Result { public ERROR_TYPE expectErr(String message) { return unwrapErrOrElseThrow(() -> new IllegalStateException(message)); } }
Result { public ERROR_TYPE expectErr(String message) { return unwrapErrOrElseThrow(() -> new IllegalStateException(message)); } Result(); }
Result { public ERROR_TYPE expectErr(String message) { return unwrapErrOrElseThrow(() -> new IllegalStateException(message)); } 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 ERROR_TYPE expectErr(String message) { return unwrapErrOrElseThrow(() -> new IllegalStateException(message)); } 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();  }