Class Assert


  • public class Assert
    extends java.lang.Object
    Collection of static assert methods not provided by the JUnit framework. Use it equivalent to the JUnit Assert class by a static import.
    • Constructor Summary

      Constructors 
      Constructor Description
      Assert()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertCollection​(java.lang.String message, java.util.Collection expected, java.util.Collection actual)
      Asserts that expected and actual collection contain the same elements and have the same size.
      static void assertCollection​(java.util.Collection expected, java.util.Collection actual)
      Asserts that expected and actual collection contain the same elements and have the same size.
      static void assertCollectionElements​(java.util.Collection actual, java.lang.Object... objects)
      Asserts that actual collection contains only given objects.
      static void assertEquals​(java.lang.Object expected, java.lang.Object actual)
      Extend equality check for objects.
      static void assertNotEquals​(java.lang.Object expected, java.lang.Object actual)
      Asserts that two objects are not equal.
      static void assertNotEquals​(java.lang.String message, java.lang.Object expected, java.lang.Object actual)
      Asserts that two objects are not equal.
      static <T extends java.lang.Comparable>
      void
      assertValueInRange​(java.lang.String message, T lowerLimit, T upperLimit, T actual)
      Asserts that expected value belongs to a given numerical range .
      static <T extends java.lang.Comparable>
      void
      assertValueInRange​(T lowerLimit, T upperLimit, T actual)
      Asserts that expected value belongs to a given numerical range .
      static java.util.List list()
      Returns an immutable empty list.
      static java.util.List list​(java.lang.Object object)
      Returns an immutable list containing the given argument.
      static java.util.List list​(java.lang.Object object1, java.lang.Object object2)
      Returns a list containing the two given arguments.
      static java.util.List list​(java.lang.Object object1, java.lang.Object object2, java.lang.Object object3)
      Returns a list containing the three given arguments.
      static java.util.List list​(java.lang.Object object1, java.lang.Object object2, java.lang.Object object3, java.lang.Object object4)
      Returns an immutable list containing the four given arguments.
      static java.util.Set set()
      Gets an immutable empty set.
      static java.util.Set set​(java.lang.Object object)
      Returns an immutable set containing the given argument.
      static java.util.Set set​(java.lang.Object object1, java.lang.Object object2)
      * Returns an immutable set containing the two given arguments.
      static java.util.Set set​(java.lang.Object object1, java.lang.Object object2, java.lang.Object object3)
      Returns an immutable set containing the three given arguments.
      static java.util.Set set​(java.lang.Object object1, java.lang.Object object2, java.lang.Object object3, java.lang.Object object4)
      Returns an immutable set containing the four given arguments.
      protected <T> T singleElement​(java.util.Collection<T> collection)
      Gets the single element of the collection, or fail.
      static <T> java.util.List<T> toList​(java.util.Collection<T> collection)
      Converts the given collection to a list.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Assert

        public Assert()
    • Method Detail

      • assertCollectionElements

        public static void assertCollectionElements​(java.util.Collection actual,
                                                    java.lang.Object... objects)
        Asserts that actual collection contains only given objects.
        Parameters:
        actual - collection which has to contain only given objects
        objects - objects that has to be existent in given collection and no other one
      • assertCollection

        public static void assertCollection​(java.util.Collection expected,
                                            java.util.Collection actual)
        Asserts that expected and actual collection contain the same elements and have the same size.
        Parameters:
        expected - collection used as reference collection for the actual one
        actual - collection which has to have exactly the same elements as the expected one
      • assertValueInRange

        public static <T extends java.lang.Comparable> void assertValueInRange​(T lowerLimit,
                                                                               T upperLimit,
                                                                               T actual)
        Asserts that expected value belongs to a given numerical range .
        Parameters:
        lowerLimit - lower limit of the expected range
        upperLimit - upper limit of the expected range
        actual - actual value
      • assertValueInRange

        public static <T extends java.lang.Comparable> void assertValueInRange​(java.lang.String message,
                                                                               T lowerLimit,
                                                                               T upperLimit,
                                                                               T actual)
        Asserts that expected value belongs to a given numerical range .
        Parameters:
        message - Failure message
        lowerLimit - lower limit of the expected range
        upperLimit - upper limit of the expected range
        actual - actual value
      • assertCollection

        public static void assertCollection​(java.lang.String message,
                                            java.util.Collection expected,
                                            java.util.Collection actual)
        Asserts that expected and actual collection contain the same elements and have the same size.
        Parameters:
        expected - collection used as reference collection for the actual one
        actual - collection which has to have exactly the same elements as the expected one
        message - to show if assertion fires
      • singleElement

        protected <T> T singleElement​(java.util.Collection<T> collection)
        Gets the single element of the collection, or fail.
        Type Parameters:
        T - type of the element
        Parameters:
        collection - collection from which the single element is needed
        Returns:
        the single element contained in given collection
      • set

        public static final java.util.Set set()
        Gets an immutable empty set.
        Returns:
        an immutable empty set
      • set

        public static final java.util.Set set​(java.lang.Object object)
        Returns an immutable set containing the given argument.
        Parameters:
        object - element
        Returns:
        immutable set containing the given argument
      • set

        public static final java.util.Set set​(java.lang.Object object1,
                                              java.lang.Object object2)
        * Returns an immutable set containing the two given arguments.
        Parameters:
        object1 - first element
        object2 - second element
        Returns:
        immutable set containing the two given arguments
      • set

        public static final java.util.Set set​(java.lang.Object object1,
                                              java.lang.Object object2,
                                              java.lang.Object object3)
        Returns an immutable set containing the three given arguments.
        Parameters:
        object1 - first element
        object2 - second element
        object3 - third element
        Returns:
        immutable set containing the three given arguments
      • set

        public static final java.util.Set set​(java.lang.Object object1,
                                              java.lang.Object object2,
                                              java.lang.Object object3,
                                              java.lang.Object object4)
        Returns an immutable set containing the four given arguments.
        Parameters:
        object1 - first element
        object2 - second element
        object3 - third element
        object4 - fourth element
        Returns:
        immutable set containing the four given arguments
      • toList

        public static final <T> java.util.List<T> toList​(java.util.Collection<T> collection)
        Converts the given collection to a list.
        Type Parameters:
        T - type of collection elements
        Parameters:
        collection - collection to convert
        Returns:
        list of elements of given collection
      • list

        public static final java.util.List list()
        Returns an immutable empty list.
        Returns:
        immutable empty list
      • list

        public static final java.util.List list​(java.lang.Object object)
        Returns an immutable list containing the given argument. *
        Parameters:
        object - element
        Returns:
        immutable list containing the given argument
      • list

        public static final java.util.List list​(java.lang.Object object1,
                                                java.lang.Object object2)
        Returns a list containing the two given arguments. *
        Parameters:
        object1 - first element
        object2 - second element
        Returns:
        immutable list containing the two given arguments
      • list

        public static final java.util.List list​(java.lang.Object object1,
                                                java.lang.Object object2,
                                                java.lang.Object object3)
        Returns a list containing the three given arguments.
        Parameters:
        object1 - first element
        object2 - second element
        object3 - third element
        Returns:
        immutable list containing the three given arguments
      • list

        public static final java.util.List list​(java.lang.Object object1,
                                                java.lang.Object object2,
                                                java.lang.Object object3,
                                                java.lang.Object object4)
        Returns an immutable list containing the four given arguments.
        Parameters:
        object1 - first element
        object2 - second element
        object3 - third element
        object4 - fourth element
        Returns:
        immutable list containing the four given arguments
      • assertEquals

        public static void assertEquals​(java.lang.Object expected,
                                        java.lang.Object actual)
        Extend equality check for objects. Tests the Object.equals(Object) method in both directions and compares the result of Object.hashCode().
      • assertNotEquals

        public static void assertNotEquals​(java.lang.Object expected,
                                           java.lang.Object actual)
        Asserts that two objects are not equal. Throws an AssertionFailedError if they are equal.
      • assertNotEquals

        public static void assertNotEquals​(java.lang.String message,
                                           java.lang.Object expected,
                                           java.lang.Object actual)
        Asserts that two objects are not equal. Throws an AssertionFailedError if they are equal.