|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.fest.test.EqualsHashCodeContractAssert
public final class EqualsHashCodeContractAssert
Assertion methods that verify that an object's equals and hashCode are implemented correctly.
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
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.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||