Interface Assert<S,​A>

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      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.
      S hasSameClassAs​(java.lang.Object other)
      Verifies that the actual value has the same class as the given object.
      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 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 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.
    • Method Detail

      • isEqualTo

        S isEqualTo​(A expected)
        Verifies that the actual value is equal to the given one.
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value is not equal to the given one.
      • isNotEqualTo

        S isNotEqualTo​(A other)
        Verifies that the actual value is not equal to the given one.
        Parameters:
        other - the given value to compare the actual value to.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value is equal to the given one.
      • isNull

        void isNull()
        Verifies that the actual value is null.
        Throws:
        java.lang.AssertionError - if the actual value is not null.
      • isNotNull

        S isNotNull()
        Verifies that the actual value is not null.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value is null.
      • isSameAs

        S isSameAs​(A expected)
        Verifies that the actual value is the same as the given one.
        Parameters:
        expected - the given value to compare the actual value to.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value is not the same as the given one.
      • isNotSameAs

        S isNotSameAs​(A other)
        Verifies that the actual value is not the same as the given one.
        Parameters:
        other - the given value to compare the actual value to.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value is the same as the given one.
      • isIn

        S isIn​(A... values)
        Verifies that the actual value is present in the given array of values.
        Parameters:
        values - the given array to search the actual value in.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given array is null.
        java.lang.IllegalArgumentException - if the given array is empty.
        java.lang.AssertionError - if the actual value is not present in the given array.
      • isNotIn

        S isNotIn​(A... values)
        Verifies that the actual value is not present in the given array of values.
        Parameters:
        values - the given array to search the actual value in.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given array is null.
        java.lang.IllegalArgumentException - if the given array is empty.
        java.lang.AssertionError - if the actual value is present in the given array.
      • isIn

        S isIn​(java.lang.Iterable<? extends A> values)
        Verifies that the actual value is present in the given values.
        Parameters:
        values - the given iterable to search the actual value in.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given collection is null.
        java.lang.IllegalArgumentException - if the given collection is empty.
        java.lang.AssertionError - if the actual value is not present in the given collection.
      • isNotIn

        S isNotIn​(java.lang.Iterable<? extends A> values)
        Verifies that the actual value is not present in the given values.
        Parameters:
        values - the given iterable to search the actual value in.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given collection is null.
        java.lang.IllegalArgumentException - if the given collection is empty.
        java.lang.AssertionError - if the actual value is present in the given collection.
      • usingComparator

        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); 
         
        Parameters:
        customComparator - the comparator to use for incoming assertion checks.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given comparator is null.
      • usingDefaultComparator

        S usingDefaultComparator()
        Revert to standard comparison for incoming assertion checks.

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

        Returns:
        this assertion object.
      • isInstanceOf

        S isInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is an instance of the given type.
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given type is null.
        java.lang.AssertionError - if the actual value is null.
        java.lang.AssertionError - if the actual value is not an instance of the given type.
      • isInstanceOfAny

        S isInstanceOfAny​(java.lang.Class<?>... types)
        Verifies that the actual value is an instance of any of the given types.
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value is null.
        java.lang.AssertionError - if the actual value is not an instance of any of the given types.
        java.lang.NullPointerException - if the given array of types is null.
        java.lang.NullPointerException - if the given array of types contains nulls.
      • isNotInstanceOf

        S isNotInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is not an instance of the given type.
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given type is null.
        java.lang.AssertionError - if the actual value is null.
        java.lang.AssertionError - if the actual value is an instance of the given type.
      • isNotInstanceOfAny

        S isNotInstanceOfAny​(java.lang.Class<?>... types)
        Verifies that the actual value is not an instance of any of the given types.
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value is null.
        java.lang.AssertionError - if the actual value is an instance of any of the given types.
        java.lang.NullPointerException - if the given array of types is null.
        java.lang.NullPointerException - if the given array of types contains nulls.
      • hasSameClassAs

        S hasSameClassAs​(java.lang.Object other)
        Verifies that the actual value has the same class as the given object.
        Parameters:
        other - the object to check type against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual has not the same type has the given object.
        java.lang.NullPointerException - if the actual value is null.
        java.lang.NullPointerException - if the given object is null.
      • doesNotHaveSameClassAs

        S doesNotHaveSameClassAs​(java.lang.Object other)
        Verifies that the actual value does not have the same class as the given object.
        Parameters:
        other - the object to check type against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual has the same type has the given object.
        java.lang.NullPointerException - if the actual value is null.
        java.lang.NullPointerException - if the given object is null.
      • isExactlyInstanceOf

        S isExactlyInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is exactly an instance of the given type.
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual is not exactly an instance of given type.
        java.lang.NullPointerException - if the actual value is null.
        java.lang.NullPointerException - if the given object is null.
      • isNotExactlyInstanceOf

        S isNotExactlyInstanceOf​(java.lang.Class<?> type)
        Verifies that the actual value is not exactly an instance of given type.
        Parameters:
        type - the type to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual is exactly a instance of given type.
        java.lang.NullPointerException - if the actual value is null.
        java.lang.NullPointerException - if the given object is null.
      • isOfAnyClassIn

        S isOfAnyClassIn​(java.lang.Class<?>... types)
        Verifies that the actual value type is in given types.
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value type is not in given type.
        java.lang.NullPointerException - if the actual value is null.
        java.lang.NullPointerException - if the given types is null.
      • isNotOfAnyClassIn

        S isNotOfAnyClassIn​(java.lang.Class<?>... types)
        Verifies that the actual value type is not in given types.
        Parameters:
        types - the types to check the actual value against.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the actual value type is in given types.
        java.lang.NullPointerException - if the actual value is null.
        java.lang.NullPointerException - if the given types is null.
      • equals

        boolean equals​(java.lang.Object obj)
        Throws UnsupportedOperationException if called. It is easy to accidentally call equals(Object) instead of isEqualTo.
        Overrides:
        equals in class java.lang.Object
        Throws:
        java.lang.UnsupportedOperationException - if this method is called.