GithubHelp home page GithubHelp logo

kobee1203 / equalsverifier Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jqno/equalsverifier

0.0 1.0 0.0 5.63 MB

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

Home Page: http://www.jqno.nl/equalsverifier

License: Apache License 2.0

Java 100.00%

equalsverifier's Introduction

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.10.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

equalsverifier's People

Contributors

jqno avatar dependabot[bot] avatar dependabot-preview[bot] avatar nrbperdijk avatar mkordas avatar sullis avatar don-vip avatar stephan202 avatar ahli avatar tomcools avatar rnveach avatar scordio avatar simon04 avatar khmarbaise avatar nstdio avatar dfa1 avatar turbanoff avatar janeisklar avatar dean-allen avatar eggilbert avatar fsonntag avatar 9numbernine9 avatar bananeweizen avatar nrmancuso avatar kilink avatar romani avatar selckin avatar willpdp avatar fredster33 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.