public final class EqualsHashCodeContractAssert extends Object
equals
and hashCode
are implemented correctly.Modifier and Type | Method and Description |
---|---|
static void |
assertEqualsIsReflexive(Object obj)
Verifies that the
equals implementation of the given object is reflexive: the object must be equal to
itself, which it would be at any given instance; unless you intentionally override the equals method to behave
otherwise. |
static void |
assertEqualsIsSymmetric(Object obj1,
Object obj2)
Verifies that the
equals implementation of the given objects is symmetric: if object of one class is equal
to another class object, the other class object must be equal to this class object. |
static void |
assertEqualsIsTransitive(Object obj1,
Object obj2,
Object obj3)
Verifies that the
equals implementation of the given objects is transitive: if the first object is equal to
the second object and the second object is equal to the third object; then the first object is equal to the third
object. |
static void |
assertIsNotEqualToNull(Object obj)
Verifies that the
equals implementation of the given object returns false when the object is
compared to null . |
static void |
assertMaintainsEqualsAndHashCodeContract(Object obj1,
Object obj2)
Verifies that the
equals /hashCode contract of the given objects is implemented correctly: if two
objects are equal, then they must have the same hash code, however the opposite is NOT true. |
public static void assertIsNotEqualToNull(Object obj)
equals
implementation of the given object returns false
when the object is
compared to null
.obj
- the object to verify.AssertionError
- if the equals
implementation of the given objects returns true
when the
object compared to null
.EqualsHashCodeContractTestCase.should_not_be_equal_to_null()
public static void assertEqualsIsReflexive(Object obj)
equals
implementation of the given object is reflexive: the object must be equal to
itself, which it would be at any given instance; unless you intentionally override the equals method to behave
otherwise.obj
- the object to verify.AssertionError
- if the equals
implementation of the given object is reflexive.public static void assertEqualsIsSymmetric(Object obj1, Object obj2)
equals
implementation of the given objects is symmetric: if object of one class is equal
to another class object, the other class object must be equal to this class object. In other words, one object can
not unilaterally decide whether it is equal to another object; two objects, and consequently the classes to which
they belong, must bilaterally decide if they are equal or not. They BOTH must agree.obj1
- the object to verify.obj2
- the object to compare to.AssertionError
- if the equals
implementation of the given object is not symmetric.public static void assertEqualsIsTransitive(Object obj1, Object obj2, Object obj3)
equals
implementation of the given objects is transitive: if the first object is equal to
the second object and the second object is equal to the third object; then the first object is equal to the third
object. In other words, if two objects agree that they are equal, and follow the symmetry principle, one of them
can not decide to have a similar contract with another object of different class. All three must agree and follow
symmetry principle for various permutations of these three classes.obj1
- the object to verify.obj2
- an object to compare to.obj3
- an object to compare to.AssertionError
- if the equals
implementation of the given objects is not transitive.public static void assertMaintainsEqualsAndHashCodeContract(Object obj1, Object obj2)
equals
/hashCode
contract of the given objects is implemented correctly: if two
objects are equal, then they must have the same hash code, however the opposite is NOT true.obj1
- the object to verify.obj2
- the object to compare to.AssertionError
- if the equals
/hashCode
contract of the given objects is not implemented
correctly.Copyright © 2008–2015. All rights reserved.