Class EqualsVerifier<T>

  • Type Parameters:
    T -

    public class EqualsVerifier<T>
    extends Object
    Verifies that the equals() method of a class was correctly implemented, checking that: - An object is not equal to null - An object is equal to self - An object is equal to another similar object (created with the same arguments) - An object is not equal to objects created with different arguments
    • Method Detail

      • withArguments

        public EqualsVerifier<T> withArguments​(Object... arguments)
        Arguments are used to create a reference instance of class type. The reference instance is used to the comparisons to self, null and to another instance created with the same arguments. The types and the length of arguments must match either a visible constructor or a static method (a factory) that returns an instance of type.
        Parameters:
        arguments - an array of instances of Object.
        Returns:
        the current verifier.
      • andVariants

        public EqualsVerifier<T> andVariants​(Object... variants)
        Variants are used to create instances of type that are different from the reference instance. Each different instance is created with 1 element of variants. For instance, if arguments = {a, b, c} and variants = {d, e, f}, three different instances will be created: - Type(d, b, c) - Type(a, e, c) and - Type(a, b, f) The length of variants must be exactly the same as the length of arguments. The type of the elements of variants can be different from those of arguments. However, they must be able to assign the correspondent parameter of the constructor or factory method.
        Parameters:
        variants -
        Returns:
      • check

        public void check()
        Verifies the implementation of method equals().
      • assertIsEqual

        public static void assertIsEqual​(Object one,
                                         Object other)
      • assertNotEqual

        public static void assertNotEqual​(Object one,
                                          Object other)
      • assertNotEqualToNull

        public static void assertNotEqualToNull​(Object one)
      • assertIsEqualsToSelf

        public static void assertIsEqualsToSelf​(Object one)