@Beta @GwtCompatible public final class EqualsTester extends Object
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:
[group
i, item
j]
" refers to the
jth item in the ith equality group,
where both equality groups and the items within equality groups are
numbered starting from 1. When either a constructor argument or an
equal object is provided, that becomes group 1.
Constructor and Description |
---|
EqualsTester()
Constructs an empty EqualsTester instance
|
Modifier and Type | Method and Description |
---|---|
EqualsTester |
addEqualityGroup(Object... equalityGroup)
Adds
equalityGroup with objects that are supposed to be equal to
each other and not equal to any other equality groups added to this tester. |
EqualsTester |
testEquals()
Run tests on equals method, throwing a failure on an invalid test
|
public EqualsTester addEqualityGroup(Object... equalityGroup)
equalityGroup
with objects that are supposed to be equal to
each other and not equal to any other equality groups added to this tester.public EqualsTester testEquals()
Copyright © 2010-2014. All Rights Reserved.