When writing unit-tests, I often face the situation when equals()
for some object in tests -- in assertEquals
-- should work differently from how it wo
Copied from Object.equals(Object obj)
javadoc:
Indicates whether some other object is "equal to" this one.
The equals method implements an equivalence relation on non-null object references:
That's pretty clear to me, that is how equals should work. As for which fields to choose, you choose whichever combination of fields is required to determine whether some other object is "equal to" this one.
As for your specific case, if you, in your test, need a broader scope for equality, then you implement that in your test. You shouldn't hack your equals method just to make it fit.