To use, create a new EqualsTester and add equality groups where each group contains objects that are supposed to be equal to each other, and objects of different groups are expected to be unequal. For example:
new EqualsTester() .addEqualityGroup("hello", "h" + "ello") .addEqualityGroup("world", "wor" + "ld") .addEqualityGroup(2, 1 + 1) .testEquals();This tests:
When a test fails, the error message labels the objects involved in the failed comparison as follows:
To use, create a new EqualsTester and add equality groups where each group contains objects that are supposed to be equal to each other, and objects of different groups are expected to be unequal. For example:
new EqualsTester() .addEqualityGroup("hello", "h" + "ello") .addEqualityGroup("world", "wor" + "ld") .addEqualityGroup(2, 1 + 1) .testEquals();This tests:
public boolean equals(final Object object) { if (object != null && object.getClass() == this.getClass()) { // do check } return false; }EqualsTester ensures that the equals() and hashCode() methods have been implemented correctly.
final Object a = new Foo(4); // original object final Object b = new Foo(4); // another object that has the same values as the original final Object c = new Foo(5); // another object with different values final Object d = new Foo(4) { }; // a subclass of Foo with the same values as the original new EqualsTester(a, b, c, d);@version $Revision: 1.4 $ @author Mike Bowler
|
|
|
|
|
|