-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed as not planned
Description
When comparing abstractions (e.g. Map) via assertEquals(expected, actual), it's more likely that actual is a custom class. If there's a bug in the equals() implementation, it could be caught by calling actual.equals(expected) instead of the inverse.
For example, here's an implementation of Map.Entry that violates the equals() contract:
class EmptyEntry<K, V> implements Map.Entry<K, V> {
@Override public K getKey() { return null; }
@Override public V getValue() { return null; }
@Override public V setValue(V value) { return null; }
}This assertion passes:
assertEquals(new AbstractMap.SimpleEntry<>(null, null), new EmptyEntry<>());This assertion fails:
assertEquals(new EmptyEntry<>(), new AbstractMap.SimpleEntry<>(null, null));Shouldn't it work the other way?
bjmi