public static void checkEqualsAndHashCodeMethods(String message,Object lhs,Object rhs,boolean expectedResult){
  if ((lhs == null) && (rhs == null)) {
    Assert.assertTrue("Your check is dubious...why would you expect null != null?",expectedResult);
    return;
  }
  if ((lhs == null) || (rhs == null)) {
    Assert.assertFalse("Your check is dubious...why would you expect an object " + "to be equal to null?",expectedResult);
  }
  if (lhs != null) {
    Assert.assertEquals(message,expectedResult,lhs.equals(rhs));
  }
  if (rhs != null) {
    Assert.assertEquals(message,expectedResult,rhs.equals(lhs));
  }
  if (expectedResult) {
    String hashMessage="hashCode() values for equal objects should be the same";
    if (message != null) {
      hashMessage+=": " + message;
    }
    Assert.assertTrue(hashMessage,lhs.hashCode() == rhs.hashCode());
  }
}

public static void checkEqualsAndHashCodeMethods ( String message , Object lhs , Object rhs , boolean expectedResult ) { if ( ( lhs == null ) && ( rhs == null ) ) { Assert . assertTrue ( "Your check is dubious...why would you expect null != null?" , expectedResult ) ; return ; } if ( ( lhs == null ) || ( rhs == null ) ) { Assert . assertFalse ( "Your check is dubious...why would you expect an object " + "to be equal to null?" , expectedResult ) ; } if ( lhs != null ) { Assert . assertEquals ( message , expectedResult , lhs . equals ( rhs ) ) ; } if ( rhs != null ) { Assert . assertEquals ( message , expectedResult , rhs . equals ( lhs ) ) ; } if ( expectedResult ) { String hashMessage = "hashCode() values for equal objects should be the same" ; if ( message != null ) { hashMessage += ": " + message ; } Assert . assertTrue ( hashMessage , lhs . hashCode ( ) == rhs . hashCode ( ) ) ; } }
utility for testing equals ( ) and hashcode ( ) results at once . tests that lhs . equals ( rhs ) matches expectedresult , as well as rhs . equals ( lhs ) . also tests that hashcode ( ) return values are equal if expectedresult is true . ( hashcode ( ) is not tested if expectedresult is false , as unequal objects can have equal hashcodes . )
