• Stars
    star
    701
  • Rank 64,589 (Top 2 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.15.1</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:

@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:

@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:

profile activation purpose
modules-jdk8 JDK 8 up to but not including 11 Build only the modules that are compatible with Java 8 and up.
modules-jdk11 JDK 11 up to but not including 16 Build only the modules that are compatible with Java 11 and up.
modules-jdk16 JDK 16 Build only the modules that are compatible with Java 16 and up.
modules-jdk17 JDK 17 and up Build all modules and build releaseable artifacts.
static-analysis JDK 17 and up, and disableStaticAnalysis property must be off Run static analysis checks. This only happens on a recent JDK. Can be disabled by running mvn verify -DdisableStaticAnalysis
release-verification JDK 17 and up, and disableReleaseVerification property must be off Run release verification checks. This only happens on a recent JDK. Can be disabled by running mvn verify -DdisableReleaseVerification
argline-preview preview property must be on Enable Java preview features. Can be activated by running mvn verify -Dpreview
argline-experimental experimental property must be on Enables ByteBuddy experimental features; useful for testing EqualsVerifier on Early Access JDK builds. Can be activated by running mvn verify -Dexperimental
pitest pitest property must be on Used by PITest integration on GitHub. Can be activated by running mvn verify -Dpitest

Formatting

EqualsVerifier uses Prettier-Java through Spotless to format Java files. You can call it using mvn (without any parameters), which will also run the tests and all the other static analysis. Or run mvn spotless:apply 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:

module purpose
docs project's Jekyll website
equalsverifier-core the actual EqualsVerifier code
equalsverifier-11 tests for Java 11 and up
equalsverifier-16 logic for records, and corresponding tests
equalsverifier-17 logic for sealed classes, and corresponding tests
equalsverifier-aggregator generic release assembly description, and shared jacoco configuration
equalsverifier-release-main release assembly for jar with dependencies
equalsverifier-release-nodep release assembly for fat jar (with dependencies shaded in)
equalsverifier-release-verify validation 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

Disclaimer

Copyright 2009-2022 Jan Ouwens

More Repositories

1

equalsverifier-pre-google-code-import

This repository is no longer valid. Please update your bookmarks to the current EqualsVerifier repository.
50
star
2

dotfiles

πŸ’Ύ βš™οΈ
Lua
14
star
3

mutable-java

If Java isn't flexible enough for you
Java
11
star
4

paralleljava

Todo-Backend built with Java from a Parallel Universe
Java
9
star
5

gnome-one-window-wonderland

Gnome Shell extension that automatically maximizes new windows, leaving 'useless gaps' around them
JavaScript
8
star
6

gnome-happy-appy-hotkey

GNOME Shell extension to assign hotkeys to applications to give them focus or launch them
JavaScript
7
star
7

PicoTest

An ultra-minimal unit-testing framework, based on the JUnit 5 Platform.
Java
7
star
8

AnnotationScript

Java annotations with a lisp
Java
7
star
9

dont-hack-the-platform-talk

Slides and demo code for my talk Don't hack the platform? β˜ οΈπŸ’£πŸ’₯
7
star
10

tranquility.nvim

A configurable, tranquil colorscheme for Neovim that highlights identifiers and de-emphasizes keywords, so you can easily see what's important in your code
Lua
4
star
11

balGPT

Predicts the results of next week's soccer match!
Go
4
star
12

foobal

Predicts the results of next week's soccer match!
Scala
3
star
13

reversal.vim

A 'reversed' colorscheme for vim
HTML
3
star
14

import-pinboard

Importing my Pinboard bookmarks into Markdown files
Python
2
star
15

jqno-textobj-functioncall.vim

Vim text objects for function calls
Vim Script
1
star
16

jqno.github.io

My personal website
HTML
1
star
17

equalsverifier-talk

1
star
18

ov-herinnering

Vergeet niet uit te checken!
Scala
1
star
19

remindermail

ReminderMail is an Android app that will let you quickly send e-mail to a pre-defined address.
Kotlin
1
star
20

akka-eratosthenes

Exploring Akka using a Sieve of Eratosthenes scenario
Scala
1
star
21

advanced-scala-with-cats

I'm doing the exercises for Underscore.io's Advanced Scala with Cats and you can follow along right here!
Scala
1
star
22

reactive-stocks

Scala
1
star
23

ComposeKey.alfredsnippets

Brings the power of Linux's Compose Key to macOS through Alfred
Scala
1
star