Interface EqualsContract<T>

Type Parameters:
T - The type being tested.
All Superinterfaces:
ContractSupport<T>, ProviderSupport<T>, SupportedMethods
All Known Subinterfaces:
CollectionContract<E,C>, IterableContract<E,I>, ListContract<E,L>, ObjectContract<T>, SequencedCollectionContract<E,C>, WithString

public interface EqualsContract<T> extends ContractSupport<T>

This interface tests if a class has implemented the equals() method correctly. This contract class can be used individually by a test class, but it is normally used through the ObjectContract class:

public class MyClassTest extends ObjectContract<MyClass> {
}

If a test is using the ObjectContract class, but the class being tested does not implement the equals method based upon the specification in the Object class, then it can be omitted from the tests using the doesNotSupportMethod() method:

public class MyClassTest extends ObjectContract<MyClass> {
    public MyClassTest() {
        doesNotSupportMethod(ObjectMethods.Equals);
    }
}
Since:
1.0
Author:
evanbergstrom
See Also:
  • Method Details

    • testEqualsIsReflexive

      @Test @DisplayName("the equals() method is reflexive") default void testEqualsIsReflexive()
      Tests that the equals() method is reflexive.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also:
    • testEqualsIsSymmetric

      @Test @DisplayName("the equals() method is symmetric") default void testEqualsIsSymmetric()
      Tests that the equals() method is symmetric.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also:
    • testEqualsIsTransitive

      @Test @DisplayName("the equals() method is transitive") default void testEqualsIsTransitive()
      Tests that the equals() method is transitive.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also:
    • testEqualsIsConsistent

      @Test @DisplayName("the equals() method is consistent") default void testEqualsIsConsistent()
      Tests that the equals() method is consistent.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also:
    • testEqualsForNullValue

      @Test default void testEqualsForNullValue()
      Tests that the equals() method return false for null values.
      Throws:
      org.opentest4j.AssertionFailedError - if the test fails.
      See Also: