Class ResultAssert<S,F>
- Type Parameters:
S- type of the success value contained in theResult.F- type of the failure value contained in theResult.
- All Implemented Interfaces:
Assert<ResultAssert<S,,F>, Result<S, F>> Descriptable<ResultAssert<S,,F>> ExtensionPoints<ResultAssert<S,F>, Result<S, F>>
Result.- Author:
- Guillermo Calvo
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Method Summary
Modifier and TypeMethodDescriptionstatic <S,F> ResultAssert <S, F> assertThatResult(Result<S, F> actual) Create assertion forResult.Verifies that the actualResultis failed.hasFailure(F expectedValue) Verifies that the actualResultis a failed result containing the given value.hasFailureInstanceOf(Class<?> clazz) Verifies that the actualResultis a failed result containing a value that is an instance of the given class.hasFailureSameAs(F expectedValue) Verifies that the actualResultis a failed result containing the instance given as an argument (i.e.hasFailureSatisfying(Consumer<F> requirement) hasFailureSatisfying(Condition<? super F> condition) Verifies that the actualResultis a failed result and returns an Object assertion that allows chaining (object) assertions on its failure value.<T extends AbstractAssert<?,?>>
ThasFailureThat(InstanceOfAssertFactory<?, T> assertFactory) Verifies that the actualResultis a failed result and returns a new assertion instance to chain assertions on its failure value.Verifies that the actualResultis successful.hasSuccess(S expectedValue) Verifies that the actualResultis a successful result containing the given value.hasSuccessInstanceOf(Class<?> clazz) Verifies that the actualResultis a successful result containing a value that is an instance of the given class.hasSuccessSameAs(S expectedValue) Verifies that the actualResultis a successful result containing the instance given as an argument (i.e.hasSuccessSatisfying(Consumer<S> requirement) hasSuccessSatisfying(Condition<? super S> condition) Verifies that the actualResultis a successful result and returns an Object assertion that allows chaining (object) assertions on its success value.<T extends AbstractAssert<?,?>>
ThasSuccessThat(InstanceOfAssertFactory<?, T> assertFactory) Verifies that the actualResultis a successful result and returns a new assertion instance to chain assertions on its success value.Methods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, inBinary, inHexadecimal, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, usingEquals, usingEquals, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs, describedAs
-
Method Details
-
assertThatResult
Create assertion forResult.This static method is provided for convenience, in case
ResultAssertions.assertThat(Result)can't be statically imported. -
hasSuccess
Verifies that the actualResultis successful.Assertions will pass:
Assertions will fail:assertThat(Results.success("yay")).hasSuccess(); assertThat(Results.success(123)).hasSuccess();assertThat(Results.failure("nay")).hasSuccess(); assertThat(Results.failure(123)).hasSuccess();- Returns:
- this assertion object.
-
hasSuccess
Verifies that the actualResultis a successful result containing the given value.Assertions will pass:
Assertions will fail:assertThat(Results.success("yay")).hasSuccess("yay"); assertThat(Results.success(1234)).hasSuccess(1234);assertThat(Results.success("yay")).hasSuccess("nay"); assertThat(Results.failure("yay")).hasSuccess("yay");- Parameters:
expectedValue- the expected success value inside theResult.- Returns:
- this assertion object.
-
hasSuccessSameAs
Verifies that the actualResultis a successful result containing the instance given as an argument (i.e. it must be the same instance).Given:
Assertions will pass:static { final String FOOBAR = "foobar"; }
Assertions will fail:assertThat(Results.success(FOOBAR)).hasSuccessSameAs(FOOBAR); assertThat(Results.success(10)).hasSuccessSameAs(10);assertThat(Results.success("yay")).hasSuccessSameAs("nay"); assertThat(Results.failure(FOOBAR)).hasSuccessSameAs(FOOBAR);- Parameters:
expectedValue- the expected success value inside theResult.- Returns:
- this assertion object.
-
hasSuccessSatisfying
Verifies that the actualResultis a successful result and invokes the givenConsumerwith the success value for further assertions.Should be used as a way of deeper asserting on the containing object, as further requirement(s) for the value.
Assertions will pass:
Assertions will fail:// one requirement assertThat(Results.success(10)).hasSuccessSatisfying(s -> { assertThat(s).isGreaterThan(9); }); assertThat(Results.success("yay")).hasSuccessSatisfying(s -> { assertThat(s).isEqualTo("yay"); }); // multiple requirements assertThat(Results.success("hello")).hasSuccessSatisfying(s -> { assertThat(s).isEqualTo("hello"); assertThat(s).startsWith("h"); assertThat(s).endsWith("o"); });assertThat(Results.success("yay")).hasSuccessSatisfying(s -> assertThat(s).isEqualTo("nay")); assertThat(Results.failure("yay")).hasSuccessSatisfying(s -> {});- Parameters:
requirement- to further assert on the success value held by theResult- Returns:
- this assertion object.
-
hasSuccessSatisfying
Verifies that the actualResultis a successful result whose success value satisfies the givenCondition.Given:
Assertion will pass:static { final Condition<Integer> IS_NEGATIVE = new Condition<>(i -> i < 0, "a negative number"); }
Assertions will fail:assertThat(Results.success(-1)).hasSuccessSatisfying(IS_NEGATIVE);assertThat(Results.success(1234)).hasSuccessSatisfying(IS_NEGATIVE); assertThat(Results.failure(-123)).hasSuccessSatisfying(IS_NEGATIVE);- Parameters:
condition- the given condition- Returns:
- this assertion object.
-
hasSuccessInstanceOf
Verifies that the actualResultis a successful result containing a value that is an instance of the given class.Assertions will pass:
Assertions will fail:assertThat(Results.success("hello")) .hasSuccessInstanceOf(String.class) .hasSuccessInstanceOf(Object.class); assertThat(Results.success(1234)).hasSuccessInstanceOf(Integer.class);assertThat(Results.success("hello")).hasSuccessInstanceOf(Integer.class); assertThat(Results.failure("hello")).hasSuccessInstanceOf(String.class);- Parameters:
clazz- the expected class of the success value inside theResult- Returns:
- this assertion object.
-
hasSuccessThat
Verifies that the actualResultis a successful result and returns an Object assertion that allows chaining (object) assertions on its success value.Assertions will pass:
Assertions will fail:assertThat(Results.success(0)).hasSuccessThat().isZero(); assertThat(Results.success(100)).hasSuccessThat().isGreaterThan(10);assertThat(Results.failure(0)).hasSuccessThat().isZero(); assertThat(Results.success(1)).hasSuccessThat().isGreaterThan(10);- Returns:
- a new
ObjectAssertfor assertions chaining on the success value. - See Also:
-
hasSuccessThat
public <T extends AbstractAssert<?,?>> T hasSuccessThat(InstanceOfAssertFactory<?, T> assertFactory) Verifies that the actualResultis a successful result and returns a new assertion instance to chain assertions on its success value.The
assertFactoryparameter allows to specify anInstanceOfAssertFactory, which is used to get the assertions narrowed to the factory type.Wrapping the given
InstanceOfAssertFactorywithAssertions.as(InstanceOfAssertFactory)makes the assertion more readable.Assertions will pass:
Assertions will fail:assertThat(Results.success(0)).hasSuccessThat(as(InstanceOfAssertFactories.INTEGER)).isZero(); assertThat(Results.success("hello")).hasSuccessThat(as(InstanceOfAssertFactories.STRING)).startsWith("h");assertThat(Results.success("hello")).hasSuccessThat(as(InstanceOfAssertFactories.INTEGER)).isZero(); assertThat(Results.failure("hello")).hasSuccessThat(as(InstanceOfAssertFactories.STRING)).startsWith("h");- Type Parameters:
T- the type of the resultingAssert- Parameters:
assertFactory- the factory which verifies the type and creates the newAssert- Returns:
- a new narrowed
ObjectAssertProxyinstance for assertions chaining on the success value
-
hasFailure
Verifies that the actualResultis failed.Assertions will pass:
Assertions will fail:assertThat(Results.failure("yay")).hasFailure(); assertThat(Results.failure(123)).hasFailure();assertThat(Results.success("nay")).hasFailure(); assertThat(Results.success(123)).hasFailure();- Returns:
- this assertion object.
-
hasFailure
Verifies that the actualResultis a failed result containing the given value.Assertions will pass:
Assertions will fail:assertThat(Results.failure("yay")).hasFailure("yay"); assertThat(Results.failure(1234)).hasFailure(1234);assertThat(Results.failure("yay")).hasFailure("nay"); assertThat(Results.success("yay")).hasFailure("yay");- Parameters:
expectedValue- the expected failure value inside theResult.- Returns:
- this assertion object.
-
hasFailureSameAs
Verifies that the actualResultis a failed result containing the instance given as an argument (i.e. it must be the same instance).Given:
Assertions will pass:static { final String FOOBAR = "foobar"; }
Assertions will fail:assertThat(Results.failure(FOOBAR)).hasFailureSameAs(FOOBAR); assertThat(Results.failure(10)).hasFailureSameAs(10);// not equal: assertThat(Results.failure("yay")).hasFailureSameAs("nay"); assertThat(Results.success(FOOBAR)).hasFailureSameAs(FOOBAR);- Parameters:
expectedValue- the expected failure value inside theResult.- Returns:
- this assertion object.
-
hasFailureSatisfying
Verifies that the actualResultis a failed result and invokes the givenConsumerwith the failure value for further assertions.Should be used as a way of deeper asserting on the containing object, as further requirement(s) for the value.
Assertions will pass:
Assertions will fail:// one requirement assertThat(Results.failure(10)).hasFailureSatisfying(f -> { assertThat(f).isGreaterThan(9); }); assertThat(Results.failure("yay")).hasFailureSatisfying(f -> { assertThat(f).isEqualTo("yay"); }); // multiple requirements assertThat(Results.failure("hello")).hasFailureSatisfying(f -> { assertThat(f).isEqualTo("hello"); assertThat(f).startsWith("h"); assertThat(f).endsWith("o"); });assertThat(Results.success("hello")).hasSuccessSatisfying(s -> assertThat(s).isEqualTo("hello")); assertThat(Results.failure("hello")).hasSuccessSatisfying(s -> {});- Parameters:
requirement- to further assert on the failure value held by theResult- Returns:
- this assertion object.
-
hasFailureSatisfying
Verifies that the actualResultis a failed result whose failure value satisfies the givenCondition.Given:
Assertion will pass:static { final Condition<Integer> IS_NEGATIVE = new Condition<>(i -> i < 0, "a negative number"); }
Assertions will fail:assertThat(Results.failure(-1)).hasFailureSatisfying(IS_NEGATIVE);assertThat(Results.failure(1234)).hasFailureSatisfying(IS_NEGATIVE); assertThat(Results.success(-123)).hasFailureSatisfying(IS_NEGATIVE);- Parameters:
condition- the given condition- Returns:
- this assertion object.
-
hasFailureInstanceOf
Verifies that the actualResultis a failed result containing a value that is an instance of the given class.Assertions will pass:
Assertions will fail:assertThat(Results.failure("hello")) .hasFailureInstanceOf(String.class) .hasFailureInstanceOf(Object.class); assertThat(Results.failure(123)).hasSuccessInstanceOf(Integer.class);assertThat(Results.failure("hello")).hasFailureInstanceOf(Integer.class); assertThat(Results.success("hello")).hasFailureInstanceOf(String.class);- Parameters:
clazz- the expected class of the failure value inside theResult- Returns:
- this assertion object.
-
hasFailureThat
Verifies that the actualResultis a failed result and returns an Object assertion that allows chaining (object) assertions on its failure value.Assertions will pass:
Assertions will fail:assertThat(Results.failure(10)).hasFailureThat().isZero(); assertThat(Results.failure(100)).hasFailureThat().isGreaterThan(10);assertThat(Results.success(0)).hasFailureThat().isZero(); assertThat(Results.failure(1)).hasFailureThat().isGreaterThan(10);- Returns:
- a new
ObjectAssertfor assertions chaining on the success value. - See Also:
-
hasFailureThat
public <T extends AbstractAssert<?,?>> T hasFailureThat(InstanceOfAssertFactory<?, T> assertFactory) Verifies that the actualResultis a failed result and returns a new assertion instance to chain assertions on its failure value.The
assertFactoryparameter allows to specify anInstanceOfAssertFactory, which is used to get the assertions narrowed to the factory type.Wrapping the given
InstanceOfAssertFactorywithAssertions.as(InstanceOfAssertFactory)makes the assertion more readable.Assertions will pass:
Assertions will fail:assertThat(Results.failure(0)).hasFailureThat(as(InstanceOfAssertFactories.INTEGER)).isZero(); assertThat(Results.failure("hello")).hasFailureThat(as(InstanceOfAssertFactories.STRING)).startsWith("h");assertThat(Results.failure("hello")).hasFailureThat(as(InstanceOfAssertFactories.INTEGER)).isZero(); assertThat(Results.success("hello")).hasFailureThat(as(InstanceOfAssertFactories.STRING)).startsWith("h");- Type Parameters:
T- the type of the resultingAssert- Parameters:
assertFactory- the factory which verifies the type and creates the newAssert- Returns:
- a new narrowed
ObjectAssertProxyinstance for assertions chaining on the success value
-