Socket
Socket
Sign inDemoInstall

nl.jqno.equalsverifier:equalsverifier

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nl.jqno.equalsverifier:equalsverifier

EqualsVerifier can be used in JUnit unit tests to verify whether the contract for the equals and hashCode methods is met.


Version published
Maintainers
1
Source

EqualsVerifier

Apache License 2.0 Maven Central Javadoc

Build Status SemVer stability Issue resolution

EqualsVerifier can be used in Java unit tests to verify whether the contract for the equals and hashCode methods in a class is met.

Getting Started

EqualsVerifier's Maven coordinates are:

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

(Note that there's also a 'fat' jar with no transitive dependencies with artifactId equalsverifier-nodep.)

Now you can write a test:

import nl.jqno.equalsverifier.*;

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

EqualsVerifier is an opinionated library, which means that it can be quite strict. If you feel it's too much, you can make it more lenient:

import nl.jqno.equalsverifier.*;

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

This way, EqualsVerifier will throw less errors at you. However, it's usually better to just fix the errors: EqualsVerifier throws them for a reason!

For more information, please see the project's website.

Prefer to watch a short video?

EqualsVerifier getting started video by Tom Cools

Video by Tom Cools

A note on equality

EqualsVerifier cares about bug-free equality, in Java and in real life. The place where a person happens to be born, the colour of their skin, their gender, or the person they happen to love, must not affect the way they are treated in life. If it does, that's a bug and it should throw an error.

Don't allow bugs in your equality.

🌈🧑🏻‍🤝‍🧑🏾🌍

Contribution

Pull requests are welcome! If you plan to open one, please also register an issue or send a message to the Google Group, so we can discuss it first. It would be a shame to put in a lot of work on something that isn't a good fit for the project. Also, I can help you by giving pointers on where to find certain things.

Development

Build

To build EqualsVerifier, you need Maven. Just call mvn from the command-line, without any parameters, and you're done. Alternatively, you can use any IDE with Maven support.

There are several Maven profiles that can be enabled or disabled:

profileactivationpurpose
modules-jdk8JDK 8 up to but not including 11Build only the modules that are compatible with Java 8 and up.
modules-jdk11JDK 11 up to but not including 16Build only the modules that are compatible with Java 11 and up.
modules-jdk16JDK 16Build only the modules that are compatible with Java 16 and up.
modules-jdk17JDK 17 and upBuild all modules and build releaseable artifacts.
static-analysisJDK 17 and up, and disableStaticAnalysis property must be offRun static analysis checks. This only happens on a recent JDK. Can be disabled by running mvn verify -DdisableStaticAnalysis
release-verificationJDK 17 and up, and disableReleaseVerification property must be offRun release verification checks. This only happens on a recent JDK. Can be disabled by running mvn verify -DdisableReleaseVerification
argline-previewpreview property must be onEnable Java preview features. Can be activated by running mvn verify -Dpreview
argline-experimentalexperimental property must be onEnables ByteBuddy experimental features; useful for testing EqualsVerifier on Early Access JDK builds. Can be activated by running mvn verify -Dexperimental
pitestpitest property must be onUsed by PITest integration on GitHub. Can be activated by running mvn verify -Dpitest

Formatting

EqualsVerifier uses Prettier-Java through prettier-maven-plugin to format Java files. You can call it using mvn clean verify, or run mvn prettier:write to only run the formatter.

Modules

This project is a multi-module project to make it easier to deal with shading and multi-release jar files. See this question on StackOverflow for the rationale behind it.

Here's a description of the modules:

modulepurpose
docsproject's Jekyll website
equalsverifier-corethe actual EqualsVerifier code
equalsverifier-11logic for modules, tests for Java 11 and up
equalsverifier-16logic for records, and corresponding tests
equalsverifier-17logic for sealed classes, and corresponding tests
equalsverifier-21tests for record pattern matching
equalsverifier-aggregatorgeneric release assembly description, and shared jacoco configuration
equalsverifier-release-mainrelease assembly for jar with dependencies
equalsverifier-release-nodeprelease assembly for fat jar (with dependencies shaded in)
equalsverifier-release-verifyvalidation tests for the releases

Signed JAR

The lib/ folder in the equalsverifier-test-core module contains a local Maven repository containing a signed JAR, used to test potential ClassLoader issues. Here's how to install a JAR into it:

mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file \
                        -Dfile=&lt;path-to-file> -DgroupId=&lt;myGroup> \
                        -DartifactId=&lt;myArtifactId> -Dversion=&lt;myVersion> \
                        -Dpackaging=&lt;myPackaging> -DcreateChecksum=true \
                        -DlocalRepositoryPath=equalsverifier-test-core/lib

The signed JAR itself can be found in this repo.

Website

To generate the website

  • Using Docker: start the server by running docker-compose up or docker compose run jekyll serve.
  • Using Jekyll: install the Ruby 3.x toolchain and run bundle exec jekyll serve --watch

Note that thepage uses the TilburgsAns font but references it from the main site at jqno.nl. In development, it will fall back to a sans-serif font. See the font license here.

Disclaimer

Copyright 2009-2024 Jan Ouwens

FAQs

Package last updated on 23 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc