Have you ever written an equals method, along with five screens of unit tests to test it? Or worse: not bothered to test it at all, because “the IDE generates it anyway”?

EqualsVerifier helps you. Testing equals can be as simple as:

@Test
public void equalsContract() {
    EqualsVerifier.forClass(Foo.class).verify();
}

If you feel EqualsVerifier is too strict, you can make it more lenient:

@Test
public void simpleEqualsContract() {
    EqualsVerifier.simple().forClass(Foo.class).verify();
}

And EqualsVerifier even gives you 100% coverage on equals and hashCode methods.

Don’t forget to add it to your build!

<dependency>
    <groupId>nl.jqno.equalsverifier</groupId>
    <artifactId>equalsverifier</artifactId>
    <version>3.8.2</version>
    <scope>test</scope>
</dependency>