Class AbstractAssert<S extends AbstractAssert<S,​A>,​A>

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected A actual  
      protected S myself  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractAssert​(A actual, java.lang.Class<?> selfType)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      S as​(java.lang.String description)
      Sets the description of this object.
      S as​(Description description)
      Sets the description of this object.
      S describedAs​(java.lang.String description)
      Alias for Descriptable.as(String) since "as" is a keyword in Groovy.
      S describedAs​(Description description)
      Alias for Descriptable.as(String) since "as" is a keyword in Groovy.
      java.lang.String descriptionText()
      The description of this assertion set with describedAs(String) or describedAs(Description).
      S doesNotHave​(Condition<? super A> condition)
      Verifies that the actual value does not satisfy the given condition.
      S doesNotHaveSameClassAs​(java.lang.Object other)
      Verifies that the actual value does not have the same class as the given object.
      boolean equals​(java.lang.Object obj)
      Throws UnsupportedOperationException if called.
      protected WritableAssertionInfo getWritableAssertionInfo()
      Exposes the WritableAssertionInfo used in the current assertion for better extensibility.
      When writing your own assertion class, you can use the returned WritableAssertionInfo to change the error message and still keep the description set by the assertion user.
      S has​(Condition<? super A> condition)
      Verifies that the actual value satisfies the given condition.
      int hashCode()
      Always returns 1.
      S hasSameClassAs​(java.lang.Object other)
      Verifies that the actual value has the same class as the given object.
      S is​(Condition<? super A> condition)
      Verifies that the actual value satisfies the given condition.
      S isEqualTo​(A expected)
      Verifies that the actual value is equal to the given one.
      S isExactlyInstanceOf​(java.lang.Class<?> type)
      Verifies that the actual value is exactly an instance of the given type.
      S isIn​(A... values)
      Verifies that the actual value is present in the given array of values.
      S isIn​(java.lang.Iterable<? extends A> values)
      Verifies that the actual value is present in the given values.
      S isInstanceOf​(java.lang.Class<?> type)
      Verifies that the actual value is an instance of the given type.
      S isInstanceOfAny​(java.lang.Class<?>... types)
      Verifies that the actual value is an instance of any of the given types.
      S isNot​(Condition<? super A> condition)
      Verifies that the actual value does not satisfy the given condition.
      S isNotEqualTo​(A other)
      Verifies that the actual value is not equal to the given one.
      S isNotExactlyInstanceOf​(java.lang.Class<?> type)
      Verifies that the actual value is not exactly an instance of given type.
      S isNotIn​(A... values)
      Verifies that the actual value is not present in the given array of values.
      S isNotIn​(java.lang.Iterable<? extends A> values)
      Verifies that the actual value is not present in the given values.
      S isNotInstanceOf​(java.lang.Class<?> type)
      Verifies that the actual value is not an instance of the given type.
      S isNotInstanceOfAny​(java.lang.Class<?>... types)
      Verifies that the actual value is not an instance of any of the given types.
      S isNotNull()
      Verifies that the actual value is not null.
      S isNotOfAnyClassIn​(java.lang.Class<?>... types)
      Verifies that the actual value type is not in given types.
      S isNotSameAs​(A other)
      Verifies that the actual value is not the same as the given one.
      void isNull()
      Verifies that the actual value is null.
      S isOfAnyClassIn​(java.lang.Class<?>... types)
      Verifies that the actual value type is in given types.
      S isSameAs​(A expected)
      Verifies that the actual value is the same as the given one.
      S overridingErrorMessage​(java.lang.String newErrorMessage, java.lang.Object... args)
      Overrides Fest default error message by the given one, the new error message can be built using String.format(String, Object...), hence the presence of args parameter.
      S usingComparator​(java.util.Comparator<? super A> customComparator)
      Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
      S usingDefaultComparator()
      Revert to standard comparison for incoming assertion checks.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • actual

        protected final A actual
    • Constructor Detail

      • AbstractAssert

        protected AbstractAssert​(A actual,
                                 java.lang.Class<?> selfType)
    • Method Detail

      • as

        public S as​(Description description)
        Sets the description of this object. To remove or clear the description, pass a EmptyTextDescription as argument.

        This overloaded version of "describedAs" offers more flexibility than the one taking a String by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.

        Specified by:
        as in interface Descriptable<S extends AbstractAssert<S,​A>>
        Parameters:
        description - the new description to set.
        Returns:
        this object.
        See Also:
        Descriptable.describedAs(Description)
      • describedAs

        public S describedAs​(Description description)
        Alias for Descriptable.as(String) since "as" is a keyword in Groovy. To remove or clear the description, pass a EmptyTextDescription as argument.

        This overloaded version of "describedAs" offers more flexibility than the one taking a String by allowing users to pass their own implementation of a description. For example, a description that creates its value lazily, only when an assertion failure occurs.

        Specified by:
        describedAs in interface Descriptable<S extends AbstractAssert<S,​A>>
        Parameters:
        description - the new description to set.
        Returns:
        this object.
      • isEqualTo

        public S isEqualTo​(A expected)
        Verifies that the actual value is equal to the given one.
        Specified by:
        isEqualTo in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
      • isNotEqualTo

        public S isNotEqualTo​(A other)
        Verifies that the actual value is not equal to the given one.
        Specified by:
        isNotEqualTo in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        other - the given value to compare the actual value to.
        Returns:
        this assertion object.
      • isNull

        public void isNull()
        Verifies that the actual value is null.
        Specified by:
        isNull in interface Assert<S extends AbstractAssert<S,​A>,​A>
      • isNotNull

        public S isNotNull()
        Verifies that the actual value is not null.
        Specified by:
        isNotNull in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Returns:
        this assertion object.
      • isSameAs

        public S isSameAs​(A expected)
        Verifies that the actual value is the same as the given one.
        Specified by:
        isSameAs in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
      • isNotSameAs

        public S isNotSameAs​(A other)
        Verifies that the actual value is not the same as the given one.
        Specified by:
        isNotSameAs in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        other - the given value to compare the actual value to.
        Returns:
        this assertion object.
      • isIn

        public S isIn​(A... values)
        Verifies that the actual value is present in the given array of values.
        Specified by:
        isIn in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        values - the given array to search the actual value in.
        Returns:
        this assertion object.
      • isNotIn

        public S isNotIn​(A... values)
        Verifies that the actual value is not present in the given array of values.
        Specified by:
        isNotIn in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        values - the given array to search the actual value in.
        Returns:
        this assertion object.
      • isIn

        public S isIn​(java.lang.Iterable<? extends A> values)
        Verifies that the actual value is present in the given values.
        Specified by:
        isIn in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        values - the given iterable to search the actual value in.
        Returns:
        this assertion object.
      • isNotIn

        public S isNotIn​(java.lang.Iterable<? extends A> values)
        Verifies that the actual value is not present in the given values.
        Specified by:
        isNotIn in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        values - the given iterable to search the actual value in.
        Returns:
        this assertion object.
      • isInstanceOf

        public S isInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is an instance of the given type.
        Specified by:
        isInstanceOf in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isInstanceOfAny

        public S isInstanceOfAny​(java.lang.Class<?>... types)
        Verifies that the actual value is an instance of any of the given types.
        Specified by:
        isInstanceOfAny in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • isNotInstanceOf

        public S isNotInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is not an instance of the given type.
        Specified by:
        isNotInstanceOf in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isNotInstanceOfAny

        public S isNotInstanceOfAny​(java.lang.Class<?>... types)
        Verifies that the actual value is not an instance of any of the given types.
        Specified by:
        isNotInstanceOfAny in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • hasSameClassAs

        public S hasSameClassAs​(java.lang.Object other)
        Verifies that the actual value has the same class as the given object.
        Specified by:
        hasSameClassAs in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        other - the object to check type against.
        Returns:
        this assertion object.
      • doesNotHaveSameClassAs

        public S doesNotHaveSameClassAs​(java.lang.Object other)
        Verifies that the actual value does not have the same class as the given object.
        Specified by:
        doesNotHaveSameClassAs in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        other - the object to check type against.
        Returns:
        this assertion object.
      • isExactlyInstanceOf

        public S isExactlyInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is exactly an instance of the given type.
        Specified by:
        isExactlyInstanceOf in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isNotExactlyInstanceOf

        public S isNotExactlyInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is not exactly an instance of given type.
        Specified by:
        isNotExactlyInstanceOf in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
      • isOfAnyClassIn

        public S isOfAnyClassIn​(java.lang.Class<?>... types)
        Verifies that the actual value type is in given types.
        Specified by:
        isOfAnyClassIn in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • isNotOfAnyClassIn

        public S isNotOfAnyClassIn​(java.lang.Class<?>... types)
        Verifies that the actual value type is not in given types.
        Specified by:
        isNotOfAnyClassIn in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
      • descriptionText

        public java.lang.String descriptionText()
        The description of this assertion set with describedAs(String) or describedAs(Description).
        Returns:
        the description String representation of this assertion.
      • overridingErrorMessage

        public S overridingErrorMessage​(java.lang.String newErrorMessage,
                                        java.lang.Object... args)
        Overrides Fest default error message by the given one, the new error message can be built using String.format(String, Object...), hence the presence of args parameter.

        Example :

         assertThat(player.isRookie()).overridingErrorMessage("Expecting Player <%s> to be a rookie but was not.", player)
             .isTrue();
         
        Parameters:
        newErrorMessage - the error message that will replace the default one provided by Fest.
        args - the args used to fill error message as in String.format(String, Object...).
        Returns:
        this assertion object.
        Throws:
        exception - see String.format(String, Object...) exception clause.
      • usingComparator

        public S usingComparator​(java.util.Comparator<? super A> customComparator)
        Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.

        Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.

        Examples :

         // frodo and sam are instances of Character with Hobbit race (obviously :).
         // raceComparator implements Comparator<Character> 
         assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam); 
         
        Specified by:
        usingComparator in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Parameters:
        customComparator - the comparator to use for incoming assertion checks.
        Returns:
        this assertion object.
      • equals

        public final boolean equals​(java.lang.Object obj)
        Throws UnsupportedOperationException if called. It is easy to accidentally call Assert.equals(Object) instead of isEqualTo.
        Specified by:
        equals in interface Assert<S extends AbstractAssert<S,​A>,​A>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public final int hashCode()
        Always returns 1.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        1.