Class EitherAssert<LEFT,​RIGHT>

  • Type Parameters:
    LEFT - type of the value on the left contained in the Either.
    RIGHT - type of the value on the right contained in the Either.
    All Implemented Interfaces:
    org.assertj.core.api.Assert<EitherAssert<LEFT,​RIGHT>,​io.vavr.control.Either<LEFT,​RIGHT>>, org.assertj.core.api.Descriptable<EitherAssert<LEFT,​RIGHT>>, org.assertj.core.api.ExtensionPoints<EitherAssert<LEFT,​RIGHT>,​io.vavr.control.Either<LEFT,​RIGHT>>

    public class EitherAssert<LEFT,​RIGHT>
    extends org.assertj.core.api.AbstractObjectAssert<SELF,​ACTUAL>
    Assertions for Either.
    Author:
    Alex Dukhno
    • Field Summary

      • Fields inherited from class org.assertj.core.api.AbstractAssert

        actual, info, myself, throwUnsupportedExceptionOnEquals
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      ACTUAL actual()  
      SELF containsLeftInstanceOf​(Class<?> clazz)
      Verifies that the actual left-sided Either contains a value that is an instance of the argument.
      SELF containsLeftSame​(LEFT expectedValue)
      Verifies that the actual Either contains the instance given as an argument as the left value.
      SELF containsOnLeft​(LEFT expectedValue)
      Verifies that the actual Either is Either.Left and contains the given value.
      SELF containsOnRight​(RIGHT expectedValue)
      Verifies that the actual Either is Either.Right and contains the given value.
      SELF containsRightInstanceOf​(Class<?> clazz)
      Verifies that the actual right-sided Either contains a value that is an instance of the argument.
      SELF containsRightSame​(RIGHT expectedValue)
      Verifies that the actual Either contains the instance given as an argument as the right value.
      SELF hasLeftValueSatisfying​(Consumer<LEFT> requirement)
      Verifies that the actual Either contains a left-sided value and gives this value to the given Consumer for further assertions.
      SELF hasRightValueSatisfying​(Consumer<RIGHT> requirement)
      Verifies that the actual Either contains a right-sided value and gives this value to the given Consumer for further assertions.
      org.assertj.core.api.WritableAssertionInfo info()  
      SELF isLeft()
      Verifies that the actual Either is left.
      SELF isRight()
      Verifies that the actual Either is right.
      org.assertj.core.internal.Objects objects()  
      SELF usingDefaultRightValueComparator()
      Revert to standard comparison for incoming assertion Either value checks.
      SELF usingFieldByFieldValueComparator()
      Use field/property by field/property comparison (including inherited fields/properties) instead of relying on actual type A equals method to compare the Either value's object for incoming assertion checks.
      SELF usingValueComparator​(Comparator<?> customComparator)
      Use given custom comparator instead of relying on actual type A equals method to compare the Either value's object for incoming assertion checks.
      SELF withAssertionState​(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
      • Methods inherited from interface org.assertj.core.api.Descriptable

        as, describedAs
    • Method Detail

      • isLeft

        public SELF isLeft()
        Verifies that the actual Either is left.
        Returns:
        this assertion object.
      • isRight

        public SELF isRight()
        Verifies that the actual Either is right.
        Returns:
        this assertion object.
      • containsOnRight

        public SELF containsOnRight​(RIGHT expectedValue)
        Verifies that the actual Either is Either.Right and contains the given value.
        Parameters:
        expectedValue - the expected value inside the Either.
        Returns:
        this assertion object.
      • containsOnLeft

        public SELF containsOnLeft​(LEFT expectedValue)
        Verifies that the actual Either is Either.Left and contains the given value.
        Parameters:
        expectedValue - the expected value inside the Either.
        Returns:
        this assertion object.
      • containsRightSame

        public SELF containsRightSame​(RIGHT expectedValue)
        Verifies that the actual Either contains the instance given as an argument as the right value.
        Parameters:
        expectedValue - the expected value inside the Either.
        Returns:
        this assertion object.
      • containsLeftSame

        public SELF containsLeftSame​(LEFT expectedValue)
        Verifies that the actual Either contains the instance given as an argument as the left value.
        Parameters:
        expectedValue - the expected value inside the Either.
        Returns:
        this assertion object.
      • containsRightInstanceOf

        public SELF containsRightInstanceOf​(Class<?> clazz)
        Verifies that the actual right-sided Either contains a value that is an instance of the argument.
        Parameters:
        clazz - the expected class of the value inside the right-sided Either.
        Returns:
        this assertion object.
      • containsLeftInstanceOf

        public SELF containsLeftInstanceOf​(Class<?> clazz)
        Verifies that the actual left-sided Either contains a value that is an instance of the argument.
        Parameters:
        clazz - the expected class of the value inside the left-sided Either.
        Returns:
        this assertion object.
      • hasRightValueSatisfying

        public SELF hasRightValueSatisfying​(Consumer<RIGHT> requirement)
        Verifies that the actual Either contains a right-sided value and gives this value to the given Consumer 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 :

         // one requirement
         assertThat(Either.right("something")).hasRightValueSatisfying(it -> assertThat(it).isEqualTo("something"));
        
         // multiple requirements
         assertThat(Either.right("something")).hasRightValueSatisfying(it -> {
           assertThat(it).isEqualTo("something");
           assertThat(it).startsWith("some");
           assertThat(it).endsWith("thing");
         }); 
        Assertions will fail :
        
         assertThat(Either.right("something")).hasRightValueSatisfying(it -> assertThat(it).isEqualTo("something else"));
        
         // fail because Either is left-sided, there is no value to perform assertion on
         assertThat(Either.left(42)).hasRightValueSatisfying(it -> {});
        Parameters:
        requirement - to further assert on the right-sided object contained inside the Either.
        Returns:
        this assertion object.
      • hasLeftValueSatisfying

        public SELF hasLeftValueSatisfying​(Consumer<LEFT> requirement)
        Verifies that the actual Either contains a left-sided value and gives this value to the given Consumer 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 :

         // one requirement
         assertThat(Either.left(42)).hasLeftValueSatisfying(it -> assertThat(it).isEqualTo(42));
        
         // multiple requirements
         assertThat(Either.left(42)).hasLeftValueSatisfying(it -> {
           assertThat(it).isEqualTo(42);
           assertThat(it).isLessThan(100);
           assertThat(it).isGreaterThan(0);
         }); 
        Assertions will fail :
        
         assertThat(Either.left(42)).hasLeftValueSatisfying(it -> assertThat(it).isEqualTo(24));
        
         // fail because Either is right-sided, there is no value to perform assertion on
         assertThat(Either.right("something")).hasLeftValueSatisfying(it -> {});
        Parameters:
        requirement - to further assert on the left-sided object contained inside the Either.
        Returns:
        this assertion object.
      • usingValueComparator

        public SELF usingValueComparator​(Comparator<?> customComparator)
        Use given custom comparator instead of relying on actual type A equals method to compare the Either value's object for incoming assertion checks.
        Parameters:
        customComparator - the comparator to use for incoming assertion checks.
        Returns:
        this assertion object.
        Throws:
        NullPointerException - if the given comparator is null.
      • usingFieldByFieldValueComparator

        public SELF usingFieldByFieldValueComparator()
        Use field/property by field/property comparison (including inherited fields/properties) instead of relying on actual type A equals method to compare the Either value's object for incoming assertion checks. Private fields are included but this can be disabled using Assertions.setAllowExtractingPrivateFields(boolean).
        Returns:
        this assertion object.
      • usingDefaultRightValueComparator

        public SELF usingDefaultRightValueComparator()
        Revert to standard comparison for incoming assertion Either value checks.

        This method should be used to disable a custom comparison strategy set by calling usingValueComparator(Comparator).

        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()