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
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 Summary
Modifier and TypeMethodDescriptiondefault void
Tests that theequals()
method return false for null values.default void
Tests that theequals()
method is consistent.default void
Tests that theequals()
method is reflexive.default void
Tests that theequals()
method is symmetric.default void
Tests that theequals()
method is transitive.Methods inherited from interface org.soliscode.test.contract.support.ProviderSupport
provider
Methods inherited from interface org.soliscode.test.SupportedMethods
supportsMethod
-
Method Details
-
testEqualsIsReflexive
@Test @DisplayName("the equals() method is reflexive") default void testEqualsIsReflexive()Tests that theequals()
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 theequals()
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 theequals()
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 theequals()
method is consistent.- Throws:
org.opentest4j.AssertionFailedError
- if the test fails.- See Also:
-
testEqualsForNullValue
@Test default void testEqualsForNullValue()Tests that theequals()
method return false for null values.- Throws:
org.opentest4j.AssertionFailedError
- if the test fails.- See Also:
-