/** * Assert that the {@code Result} is a success and contains the specified value. * * @param value the value the {@code Result} is expected to contain * @return this, if the wrapped object is a success and has the specified value * @throws AssertionError if the wrapped object is a failure, or does not have the specified value */ public ResultAssert hasValue(Object value) { isSuccess(); if (!actual.getValue().equals(value)) { failWithMessage("Expected Success with value: <%s> but was: <%s>", value, actual.getValue()); } return this; }
/** * Assert that the {@code Result} is a failure with the specified message. * * @param regex the regex that the failure message is expected to match * @return this, if the wrapped object is a failure with the specified message * @throws AssertionError if the wrapped object is a success, or does not have the expected message */ public ResultAssert hasFailureMessageMatching(String regex) { isFailure(); String message = actual.getFailure().getMessage(); if (!message.matches(regex)) { failWithMessage("Expected Failure with message matching: <%s> but was Failure with message: <%s>", regex, message); } return this; }
/** * Assert that the {@code Result} is a Failure. * * @return this, if the wrapped object is a failure * @throws AssertionError if the wrapped object is a success */ public ResultAssert isFailure() { isNotNull(); if (!actual.isFailure()) { failWithMessage("Expected Failure but was Success with value: <%s>", actual.getValue()); } return this; }
/** * Assert that the {@code Result} is a failure with the specified reason. * * @param expected the expected failure reason * @return this, if the wrapped object is a failure with the specified reason * @throws AssertionError if the wrapped object is a success, or does not have the expected reason */ public ResultAssert isFailure(FailureReason expected) { isFailure(); FailureReason actualReason = actual.getFailure().getReason(); if (actualReason != expected) { failWithMessage("Expected Failure with reason: <%s> but was Failure with reason: <%s>", expected, actualReason); } return this; }
/** * Assert that the {@code Result} is a Success. * * @return this, if the wrapped object is a success * @throws AssertionError if the wrapped object is a failure */ public ResultAssert isSuccess() { isNotNull(); if (!actual.isSuccess()) { Failure failure = actual.getFailure(); failWithMessage("Expected Success but was Failure with reason: <%s> and message: <%s>", failure.getReason(), failure.getMessage()); } return this; }