com.google.common.testing
Class EqualsTester

java.lang.Object
  extended by com.google.common.testing.EqualsTester

@Beta
@GwtCompatible
public final class EqualsTester
extends Object

Tester for equals() and hashCode() methods of a class.

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:

Since:
10.0
Author:
Jim McMaster, Jige Yu

Constructor Summary
EqualsTester()
          Constructs an empty EqualsTester instance
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EqualsTester

public EqualsTester()
Constructs an empty EqualsTester instance

Method Detail

addEqualityGroup

public 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.


testEquals

public EqualsTester testEquals()
Run tests on equals method, throwing a failure on an invalid test



Copyright © 2010-2012. All Rights Reserved.