Package org.assertj.vavr.api
Class TryAssert<VALUE>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
-
- org.assertj.core.api.AbstractObjectAssert<SELF,ACTUAL>
-
- org.assertj.vavr.api.TryAssert<VALUE>
-
- Type Parameters:
VALUE- type of the value contained in theTry.
- All Implemented Interfaces:
org.assertj.core.api.Assert<TryAssert<VALUE>,io.vavr.control.Try<VALUE>>,org.assertj.core.api.Descriptable<TryAssert<VALUE>>,org.assertj.core.api.ExtensionPoints<TryAssert<VALUE>,io.vavr.control.Try<VALUE>>
public class TryAssert<VALUE> extends org.assertj.core.api.AbstractObjectAssert<SELF,ACTUAL>Assertions forTry.- Author:
- Grzegorz Piwowarek
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ACTUALactual()SELFcontains(VALUE expectedValue)Verifies that the actualTrycontains the given value.SELFcontainsInstanceOf(Class<?> clazz)Verifies that the actualTrycontains a value that is an instance of the argument.SELFcontainsSame(VALUE expectedValue)Verifies that the actualTrycontains the instance given as an argument.<U extends Throwable>
SELFfailBecauseOf(Class<U> reason)Verifies that the actualTryfails because of specificThrowable.SELFfailReasonHasMessage(String exceptionMessage)Verifies that the actual @Tryfails with specific message.<U> org.assertj.vavr.api.AbstractTryAssert<?,U>flatMap(Function<? super VALUE,io.vavr.control.Try<U>> mapper)CallflatMapon theTryunder test, assertions chained afterwards are performed on theTryresulting from the flatMap call.SELFhasValueSatisfying(Consumer<VALUE> requirement)Verifies that the actualTrycontains a value and gives this value to the givenConsumerfor further assertions.SELFhasValueSatisfying(org.assertj.core.api.Condition<? super VALUE> condition)Verifies that the actualTrycontains a value which satisfies the givenCondition.org.assertj.core.api.WritableAssertionInfoinfo()SELFisFailure()Verifies that the actualTryis a failed {code Try}.SELFisSuccess()Verifies that the actualTryis a succeeded {code Try}.<U> org.assertj.vavr.api.AbstractTryAssert<?,U>map(Function<? super VALUE,? extends U> mapper)Callmapon theTryunder test, assertions chained afterwards are performed on theTryresulting from the map call.org.assertj.core.internal.Objectsobjects()SELFusingDefaultValueComparator()Revert to standard comparison for incoming assertionTryvalue checks.SELFusingFieldByFieldValueComparator()Use field/property by field/property comparison (including inherited fields/properties) instead of relying on actual type Aequalsmethod to compare theTryvalue's object for incoming assertion checks.SELFusingValueComparator(Comparator<? super VALUE> customComparator)Use given custom comparator instead of relying on actual type Aequalsmethod to compare theTryvalue's object for incoming assertion checks.SELFwithAssertionState(org.assertj.vavr.api.AbstractVavrAssert assertInstance)-
Methods inherited from class org.assertj.core.api.AbstractObjectAssert
as, as, extracting, extracting, extracting, extracting, extracting, extracting, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveComparison, usingRecursiveComparison
-
Methods inherited from class org.assertj.core.api.AbstractAssert
asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, 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, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingComparator, usingComparator, usingDefaultComparator, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnError
-
-
-
-
Method Detail
-
isSuccess
public SELF isSuccess()
Verifies that the actualTryis a succeeded {code Try}.- Returns:
- this assertion object.
-
isFailure
public SELF isFailure()
Verifies that the actualTryis a failed {code Try}.- Returns:
- this assertion object.
-
contains
public SELF contains(VALUE expectedValue)
Verifies that the actualTrycontains the given value.- Parameters:
expectedValue- the expected value inside theTry.- Returns:
- this assertion object.
-
hasValueSatisfying
public SELF hasValueSatisfying(Consumer<VALUE> requirement)
Verifies that the actualTrycontains a value and gives this value to the givenConsumerfor further assertions. Should be used as a way of deeper asserting on the containing object, as further requirement(s) for the value.- Parameters:
requirement- to further assert on the object contained inside theTry.- Returns:
- this assertion object.
-
hasValueSatisfying
public SELF hasValueSatisfying(org.assertj.core.api.Condition<? super VALUE> condition)
Verifies that the actualTrycontains a value which satisfies the givenCondition.- Parameters:
condition- the given condition.- Returns:
- this assertion object.
- Throws:
AssertionError- if the actualTryis null or empty.NullPointerException- if the given condition isnull.AssertionError- if the actual value does not satisfy the given condition.
-
containsInstanceOf
public SELF containsInstanceOf(Class<?> clazz)
Verifies that the actualTrycontains a value that is an instance of the argument.- Parameters:
clazz- the expected class of the value inside theTry.- Returns:
- this assertion object.
-
usingFieldByFieldValueComparator
public SELF usingFieldByFieldValueComparator()
Use field/property by field/property comparison (including inherited fields/properties) instead of relying on actual type Aequalsmethod to compare theTryvalue's object for incoming assertion checks. Private fields are included but this can be disabled usingAssertions.setAllowExtractingPrivateFields(boolean).- Returns:
thisassertion object.
-
usingValueComparator
public SELF usingValueComparator(Comparator<? super VALUE> customComparator)
Use given custom comparator instead of relying on actual type Aequalsmethod to compare theTryvalue's object for incoming assertion checks.- Parameters:
customComparator- the comparator to use for incoming assertion checks.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given comparator isnull.
-
usingDefaultValueComparator
public SELF usingDefaultValueComparator()
Revert to standard comparison for incoming assertionTryvalue checks.This method should be used to disable a custom comparison strategy set by calling
usingValueComparator(Comparator).- Returns:
thisassertion object.
-
containsSame
public SELF containsSame(VALUE expectedValue)
Verifies that the actualTrycontains the instance given as an argument.- Parameters:
expectedValue- the expected value inside theTry.- Returns:
- this assertion object.
-
flatMap
public <U> org.assertj.vavr.api.AbstractTryAssert<?,U> flatMap(Function<? super VALUE,io.vavr.control.Try<U>> mapper)
CallflatMapon theTryunder test, assertions chained afterwards are performed on theTryresulting from the flatMap call.- Type Parameters:
U- type of a value contained by successfulTrycreated bymapperfunction- Parameters:
mapper- theFunctionto use in theflatMapoperation.- Returns:
- a new
AbstractTryAssertfor assertions chaining on the flatMap of the Try. - Throws:
AssertionError- if the actualTryis null.
-
map
public <U> org.assertj.vavr.api.AbstractTryAssert<?,U> map(Function<? super VALUE,? extends U> mapper)
Callmapon theTryunder test, assertions chained afterwards are performed on theTryresulting from the map call.- Type Parameters:
U- type of a value created bymapperfunction- Parameters:
mapper- theFunctionto use in themapoperation.- Returns:
- a new
AbstractTryAssertfor assertions chaining on the map of the Try. - Throws:
AssertionError- if the actualTryis null.
-
failBecauseOf
public <U extends Throwable> SELF failBecauseOf(Class<U> reason)
Verifies that the actualTryfails because of specificThrowable.- Type Parameters:
U- specific type ofThrowable- Parameters:
reason- the expected exception class.- Returns:
- this assertion object.
-
failReasonHasMessage
public SELF failReasonHasMessage(String exceptionMessage)
Verifies that the actual @Tryfails with specific message.- Parameters:
exceptionMessage- the expected exception message.- Returns:
- this assertion object.
-
actual
public ACTUAL actual()
-
withAssertionState
public SELF withAssertionState(org.assertj.vavr.api.AbstractVavrAssert assertInstance)
-
objects
public org.assertj.core.internal.Objects objects()
-
info
public org.assertj.core.api.WritableAssertionInfo info()
-
-