isEqualTo should not be used to test an object for equality with itself; the assertion will never fail.


The problem

If a test subject and the argument to isEqualTo are the same instance (e.g. assertThat(x).isEqualTo(x)), then the assertion will always pass. Truth implements isEqualTo using [Objects#equal] , which tests its arguments for reference equality and returns true without calling equals() if both arguments are the same instance.

To test the implementation of an equals method, use Guava’s EqualsTester.


Suppress false positives by adding the suppression annotation @SuppressWarnings("TruthSelfEquals") to the enclosing element.