verifyEqualsAndHashCode function

void verifyEqualsAndHashCode(
  1. Object instanceA,
  2. Object instanceB
)

Verifies (using expect) that the two provided instances, which should be eqivalent (but not the same instance) are actually equal.

Arguments

  • Object instanceA - one distinct instance of the object
  • Object instanceB - another distinct instance of the object

Example

verifyEqualsAndHashCode('Alpha', 'Alpha');

Implementation

void verifyEqualsAndHashCode(Object instanceA, Object instanceB) {
  expect(instanceA, isNot(same(instanceB)));

  expect(instanceA, equals(instanceA));
  expect(instanceB, equals(instanceB));
  expect(instanceA, equals(instanceB));
  expect(instanceB, equals(instanceA));

  expect(instanceA.hashCode, equals(instanceA.hashCode));
  expect(instanceB.hashCode, equals(instanceB.hashCode));
  expect(instanceA.hashCode, equals(instanceB.hashCode));
  expect(instanceB.hashCode, equals(instanceA.hashCode));
}