├── .git-blame-ignore-revs ├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug-report.yml │ ├── config.yml │ └── feature-request.yml ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml ├── scripts │ └── next-version.sh └── workflows │ ├── ci.yml │ ├── pitest-comment.yml │ ├── pitest.yml │ └── release.yml ├── .gitignore ├── ARCHITECTURE.md ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── arcmutate-licence.txt ├── build ├── checkstyle-config.xml ├── eclipse-formatter-config.importorder └── eclipse-formatter-config.xml ├── docs ├── .gitignore ├── .notags ├── 404.html ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── _config.yml ├── _data │ ├── navigation.yml │ └── ui-text.yml ├── _errormessages │ ├── abstract-delegation.md │ ├── bigdecimal-equality.md │ ├── byte-buddy.md │ ├── class-or-field-is-not-accessible-jpms.md │ ├── classcastexception.md │ ├── coverage-is-not-100-percent.md │ ├── double-equals-doesnt-use-doublecompare-for-field-foo.md │ ├── float-equals-doesnt-use-floatcompare-for-field-foo.md │ ├── jpa-direct-reference-instead-of-getter.md │ ├── mutability-equals-depends-on-mutable-field.md │ ├── noclassdeffounderror.md │ ├── non-nullity-equals-hashcode-tostring-throws-nullpointerexception.md │ ├── precondition-two-objects-are-equal-to-each-other.md │ ├── record-failed-to-run-constructor.md │ ├── recursive-datastructure.md │ ├── redefined-superclass-object-should-not-equal-superclass-instance.md │ ├── significant-fields-equals-does-not-use-foo-or-it-is-stateless.md │ ├── significant-fields-equals-relies-on-foo-but-hashcode-does-not.md │ ├── subclass-equals-is-not-final.md │ ├── subclass-equals-subclass-instance.md │ ├── subclass-object-is-not-equal-to-an-instance-of-a-trivial-subclass-with-equal-fields.md │ ├── symmetry-does-not-equal-superclass-instance.md │ ├── transient-field.md │ ├── unable-to-make-field-accessible.md │ └── unsupported-class-file-major-version.md ├── _includes │ ├── author-profile-custom-links.html │ ├── good-equals │ ├── imagebutton_row │ └── maven ├── _manual │ ├── 00-why-what-how.md │ ├── 01-getting-started.md │ ├── 02-good-equals.md │ ├── 03-final.md │ ├── 04-immutability.md │ ├── 05-instanceof-or-getclass.md │ ├── 06-null.md │ ├── 07-ignoring-fields.md │ ├── 08-several-classes-at-once.md │ ├── 09-inheritance.md │ ├── 10-jpa-entities.md │ ├── 11-caching-hashcodes.md │ ├── 12-relaxed-equality.md │ ├── 13-legacy-systems.md │ ├── 14-jpms.md │ └── 15-prefab-values.md ├── _pages │ ├── changelog.md │ ├── errormessages.md │ ├── faq.md │ ├── index.md │ ├── inspiration.md │ ├── manual.md │ ├── migration1to2.md │ ├── migration2to3.md │ ├── migration3to4.md │ ├── resources.md │ └── submit-an-issue.md ├── assets │ └── css │ │ └── main.scss ├── docker-compose.yml └── images │ ├── error-messages.webp │ ├── getting-started.webp │ ├── manual.webp │ ├── needless-constraints.png │ └── resources.webp ├── equalsverifier-21 ├── pom.xml └── src │ ├── main │ └── java │ │ └── nl │ │ └── jqno │ │ └── equalsverifier │ │ └── internal │ │ └── versionspecific │ │ └── SequencedCollectionsHelper.java │ └── test │ └── java │ └── nl │ └── jqno │ └── equalsverifier │ └── integration │ └── extended_contract │ ├── RecordPatternMatchTest.java │ └── SequencedCollectionsClassesTest.java ├── equalsverifier-aggregator ├── pom.xml └── src │ └── main │ └── resources │ └── assemblies │ └── assembly.xml ├── equalsverifier-core ├── pom.xml └── src │ ├── main │ └── java │ │ ├── module-info.java │ │ └── nl │ │ └── jqno │ │ └── equalsverifier │ │ ├── CheckReturnValue.java │ │ ├── EqualsVerifier.java │ │ ├── EqualsVerifierReport.java │ │ ├── Func.java │ │ ├── Mode.java │ │ ├── ScanOption.java │ │ ├── Warning.java │ │ ├── api │ │ ├── ConfiguredEqualsVerifier.java │ │ ├── EqualsVerifierApi.java │ │ ├── MultipleTypeEqualsVerifierApi.java │ │ ├── RelaxedEqualsVerifierApi.java │ │ └── SingleTypeEqualsVerifierApi.java │ │ └── internal │ │ ├── ModeInstance.java │ │ ├── PrefabValuesApi.java │ │ ├── checkers │ │ ├── AbstractDelegationChecker.java │ │ ├── CachedHashCodeChecker.java │ │ ├── Checker.java │ │ ├── ExamplesChecker.java │ │ ├── FieldInspector.java │ │ ├── FieldsChecker.java │ │ ├── HierarchyChecker.java │ │ ├── MapEntryHashCodeRequirementChecker.java │ │ ├── NullChecker.java │ │ ├── RecordChecker.java │ │ ├── SignatureChecker.java │ │ └── fieldchecks │ │ │ ├── ArrayFieldCheck.java │ │ │ ├── BigDecimalFieldCheck.java │ │ │ ├── FieldCheck.java │ │ │ ├── FloatAndDoubleFieldCheck.java │ │ │ ├── JpaLazyGetterFieldCheck.java │ │ │ ├── MutableStateFieldCheck.java │ │ │ ├── NullPointerExceptionFieldCheck.java │ │ │ ├── ReflexivityFieldCheck.java │ │ │ ├── SignificantFieldCheck.java │ │ │ ├── StringFieldCheck.java │ │ │ ├── SymmetryFieldCheck.java │ │ │ ├── TransientFieldsCheck.java │ │ │ └── TransitivityFieldCheck.java │ │ ├── exceptions │ │ ├── AssertionException.java │ │ ├── EqualsVerifierInternalBugException.java │ │ ├── MessagingException.java │ │ ├── MockitoException.java │ │ ├── ModuleException.java │ │ ├── NoValueException.java │ │ ├── RecursionException.java │ │ └── ReflectionException.java │ │ ├── instantiation │ │ ├── CachingValueProvider.java │ │ ├── ChainedValueProvider.java │ │ ├── InstanceCreator.java │ │ ├── JavaApiPrefabValues.java │ │ ├── MockitoValueProvider.java │ │ ├── SubjectCreator.java │ │ ├── UserPrefabValueProvider.java │ │ ├── ValueProvider.java │ │ ├── prefab │ │ │ ├── BuiltinPrefabValueProvider.java │ │ │ ├── JavaAwtValueSupplier.java │ │ │ ├── JavaIoValueSupplier.java │ │ │ ├── JavaLangReflectValueSupplier.java │ │ │ ├── JavaLangValueSupplier.java │ │ │ ├── JavaMathValueSupplier.java │ │ │ ├── JavaNetValueSupplier.java │ │ │ ├── JavaNioValueSupplier.java │ │ │ ├── JavaRmiValueSupplier.java │ │ │ ├── JavaSqlValueSupplier.java │ │ │ ├── JavaTextValueSupplier.java │ │ │ ├── JavaTimeValueSupplier.java │ │ │ ├── JavaUtilConcurrentValueSupplier.java │ │ │ ├── JavaUtilValueSupplier.java │ │ │ ├── JavaxNamingValueSupplier.java │ │ │ ├── JavaxSwingValueSupplier.java │ │ │ ├── OthersValueSupplier.java │ │ │ ├── PrimitiveValueSupplier.java │ │ │ └── ValueSupplier.java │ │ └── vintage │ │ │ ├── FactoryCache.java │ │ │ ├── VintageValueProvider.java │ │ │ ├── factories │ │ │ ├── AbstractGenericFactory.java │ │ │ ├── EnumMapFactory.java │ │ │ ├── EnumSetFactory.java │ │ │ ├── Factories.java │ │ │ ├── FallbackFactory.java │ │ │ ├── MapFactory.java │ │ │ ├── PrefabValueFactory.java │ │ │ ├── SimpleFactory.java │ │ │ └── SimpleGenericFactory.java │ │ │ └── reflection │ │ │ ├── ClassAccessor.java │ │ │ ├── FieldModifier.java │ │ │ ├── InPlaceObjectAccessor.java │ │ │ ├── ObjectAccessor.java │ │ │ └── RecordObjectAccessor.java │ │ ├── reflection │ │ ├── ClassProbe.java │ │ ├── FieldCache.java │ │ ├── FieldIterable.java │ │ ├── FieldMutator.java │ │ ├── FieldProbe.java │ │ ├── Instantiator.java │ │ ├── ModuleProbe.java │ │ ├── PackageScanOptions.java │ │ ├── PackageScanner.java │ │ ├── RecordProbe.java │ │ ├── SealedTypesFinder.java │ │ ├── SuperclassIterable.java │ │ ├── Tuple.java │ │ ├── TypeTag.java │ │ ├── Util.java │ │ └── annotations │ │ │ ├── Annotation.java │ │ │ ├── AnnotationCache.java │ │ │ ├── AnnotationCacheBuilder.java │ │ │ ├── AnnotationClassCache.java │ │ │ ├── AnnotationProperties.java │ │ │ └── SupportedAnnotations.java │ │ ├── util │ │ ├── Assert.java │ │ ├── CachedHashCodeInitializer.java │ │ ├── Configuration.java │ │ ├── Context.java │ │ ├── ErrorMessage.java │ │ ├── ExternalLibs.java │ │ ├── FieldNameExtractor.java │ │ ├── FieldToPrefabValues.java │ │ ├── Formatter.java │ │ ├── ListBuilders.java │ │ ├── PrimitiveMappers.java │ │ ├── Rethrow.java │ │ └── Validations.java │ │ └── versionspecific │ │ └── SequencedCollectionsHelper.java │ └── test │ ├── java │ └── nl │ │ └── jqno │ │ └── equalsverifier │ │ ├── internal │ │ ├── EqualsVerifierTest.java │ │ ├── PrefabValuesApiTest.java │ │ ├── architecture │ │ │ └── ArchitectureTest.java │ │ ├── exceptions │ │ │ ├── EqualsVerifierInternalBugExceptionTest.java │ │ │ └── RecursionExceptionTest.java │ │ ├── instantiation │ │ │ ├── CachingValueProviderTest.java │ │ │ ├── ChainedValueProviderTest.java │ │ │ ├── InstanceCreatorTest.java │ │ │ ├── MockitoValueProviderTest.java │ │ │ ├── RecordInstanceCreatorTest.java │ │ │ ├── SubjectCreatorTest.java │ │ │ ├── UserPrefabValueProviderTest.java │ │ │ ├── ValueProviderTest.java │ │ │ ├── prefab │ │ │ │ └── BuiltinPrefabValueProviderTest.java │ │ │ └── vintage │ │ │ │ ├── FactoryCacheTest.java │ │ │ │ ├── VintageValueProviderCreatorTest.java │ │ │ │ ├── VintageValueProviderTest.java │ │ │ │ ├── factories │ │ │ │ ├── AbstractGenericFactoryTest.java │ │ │ │ ├── FactoriesTest.java │ │ │ │ ├── FallbackFactoryTest.java │ │ │ │ ├── MapFactoryTest.java │ │ │ │ ├── RecordFallbackFactoryTest.java │ │ │ │ ├── SealedTypesFallbackFactoryTest.java │ │ │ │ ├── SimpleFactoryTest.java │ │ │ │ └── SimpleGenericFactoryTest.java │ │ │ │ └── reflection │ │ │ │ ├── ClassAccessorTest.java │ │ │ │ ├── FieldModifierTest.java │ │ │ │ ├── InPlaceObjectAccessorCopyingTest.java │ │ │ │ ├── InPlaceObjectAccessorScramblingTest.java │ │ │ │ ├── InPlaceObjectAccessorTest.java │ │ │ │ ├── RecordObjectAccessorCopyingTest.java │ │ │ │ ├── RecordObjectAccessorScramblingTest.java │ │ │ │ └── RecordObjectAccessorTest.java │ │ ├── reflection │ │ │ ├── ClassProbeSealedTest.java │ │ │ ├── ClassProbeTest.java │ │ │ ├── FieldCacheTest.java │ │ │ ├── FieldIterableTest.java │ │ │ ├── FieldMutatorTest.java │ │ │ ├── FieldProbeTest.java │ │ │ ├── InstantiatorTest.java │ │ │ ├── PackageScannerTest.java │ │ │ ├── RecordInstantiatorTest.java │ │ │ ├── SealedTypesHelperTest.java │ │ │ ├── SuperclassIterableTest.java │ │ │ ├── TupleTest.java │ │ │ ├── TypeTagParameterizedTest.java │ │ │ ├── TypeTagTest.java │ │ │ ├── UtilTest.java │ │ │ └── annotations │ │ │ │ ├── AnnotationCacheBuilderTest.java │ │ │ │ └── SupportedAnnotationsTest.java │ │ └── util │ │ │ ├── AssertTest.java │ │ │ ├── ConfigurationHelper.java │ │ │ ├── FieldNameExtractorTest.java │ │ │ ├── FormatterTest.java │ │ │ ├── ListBuildersTest.java │ │ │ ├── RethrowTest.java │ │ │ └── ValidationsTest.java │ │ └── testhelpers │ │ ├── annotations │ │ └── TestSupportedAnnotations.java │ │ └── packages │ │ ├── annotated │ │ ├── AnnotatedPackage.java │ │ └── package-info.java │ │ ├── anonymous │ │ └── A.java │ │ ├── correct │ │ ├── A.java │ │ ├── B.java │ │ ├── C.java │ │ └── subpackage │ │ │ ├── A.java │ │ │ ├── B.java │ │ │ └── subpackage │ │ │ ├── A.java │ │ │ ├── B.java │ │ │ └── D.java │ │ ├── somerecursive │ │ ├── Nonrecursive.java │ │ ├── RecursiveA.java │ │ └── RecursiveB.java │ │ └── subclasses │ │ ├── SubA1.java │ │ ├── SubA2.java │ │ ├── SubB1.java │ │ ├── SubB2.java │ │ ├── SubI1.java │ │ ├── SubI2.java │ │ ├── SuperA.java │ │ ├── SuperB.java │ │ ├── SuperI.java │ │ └── subpackage │ │ └── SubA3.java │ └── resources │ └── simplelogger.properties ├── equalsverifier-release-main ├── pom.xml └── src │ └── main │ └── assembly │ └── assembly.xml ├── equalsverifier-release-nodep ├── pom.xml └── src │ └── main │ ├── assembly │ └── assembly.xml │ └── java │ ├── module-info.java │ └── nl │ └── jqno │ └── equalsverifier │ ├── Placeholder.java │ └── api │ └── Placeholder.java ├── equalsverifier-release-verify ├── pom.xml └── src │ └── test │ └── java │ └── nl │ └── jqno │ └── equalsverifier │ └── verify_release │ ├── jar │ ├── MainClassesJarTest.java │ ├── MainJavadocJarTest.java │ ├── MainSourcesJarTest.java │ ├── NodepClassesJarTest.java │ ├── NodepJavadocJarTest.java │ ├── NodepSourcesJarTest.java │ └── helper │ │ ├── JarAsserter.java │ │ ├── JarReader.java │ │ └── ModuleInfoAsserter.java │ └── pom │ ├── MainPomTest.java │ ├── NodepPomTest.java │ └── helper │ ├── PomAsserter.java │ └── PomReader.java ├── equalsverifier-test-jpms ├── pom.xml └── src │ ├── main │ └── java │ │ ├── module-info.java │ │ └── nl │ │ └── jqno │ │ └── equalsverifier │ │ └── jpms │ │ └── model │ │ ├── ClassPoint.java │ │ ├── ClassPointContainer.java │ │ ├── FieldsFromJdkModulesHaver.java │ │ ├── NonFinal.java │ │ └── Records.java │ └── test │ └── java │ ├── it │ ├── MockitoWorksInTheModularWorldTest.java │ ├── ModuleErrorsTest.java │ ├── SanityTest.java │ └── VintageWorksInTheModularWorldTest.java │ └── module-info.java ├── equalsverifier-test-kotlin ├── pom.xml └── src │ └── test │ └── kotlin │ └── nl │ └── jqno │ └── equalsverifier │ └── kotlin │ ├── KotlinCompilerGeneratedAnnotationTest.kt │ ├── KotlinFieldIterableTest.kt │ └── KotlinIntegrationTest.kt ├── equalsverifier-test-mockito ├── pom.xml └── src │ └── test │ └── java │ └── nl │ └── jqno │ └── equalsverifier │ └── mockito │ ├── MockitoDisableTest.java │ ├── MockitoRecursionTest.java │ ├── MockitoTest.java │ └── SanityTest.java ├── equalsverifier-test ├── lib │ └── nl │ │ └── jqno │ │ └── equalsverifier │ │ └── equalsverifier-signedjar-test │ │ ├── 0.1 │ │ ├── equalsverifier-signedjar-test-0.1.jar │ │ ├── equalsverifier-signedjar-test-0.1.jar.md5 │ │ ├── equalsverifier-signedjar-test-0.1.jar.sha1 │ │ ├── equalsverifier-signedjar-test-0.1.pom │ │ ├── equalsverifier-signedjar-test-0.1.pom.md5 │ │ └── equalsverifier-signedjar-test-0.1.pom.sha1 │ │ ├── 0.2 │ │ ├── equalsverifier-signedjar-test-0.2.jar │ │ ├── equalsverifier-signedjar-test-0.2.jar.md5 │ │ ├── equalsverifier-signedjar-test-0.2.jar.sha1 │ │ ├── equalsverifier-signedjar-test-0.2.pom │ │ ├── equalsverifier-signedjar-test-0.2.pom.md5 │ │ └── equalsverifier-signedjar-test-0.2.pom.sha1 │ │ ├── maven-metadata-local.xml │ │ ├── maven-metadata-local.xml.md5 │ │ └── maven-metadata-local.xml.sha1 ├── pom.xml └── src │ └── test │ └── java │ └── nl │ └── jqno │ └── equalsverifier │ ├── coverage │ ├── CoverageNoInheritanceTest.java │ ├── CoverageNonnullTest.java │ ├── CoverageWithInheritanceTest.java │ ├── EclipseGetClassPoint.java │ ├── EclipseInstanceOfPoint.java │ ├── HandwrittenCanEqual.java │ ├── HandwrittenGetClassPoint.java │ ├── HandwrittenInstanceOfPoint.java │ ├── IntelliJGetClassPoint.java │ ├── IntelliJInstanceOfPoint.java │ ├── LombokCanEqual.java │ ├── LombokInstanceOfPoint.java │ ├── NetBeansGetClassPoint.java │ └── PatternMatchInstanceofPoint.java │ ├── integration │ ├── basic_contract │ │ ├── HashCodeTest.java │ │ ├── NonNullityTest.java │ │ ├── ReflexivityTest.java │ │ ├── SymmetryTest.java │ │ └── TransitivityTest.java │ ├── extended_contract │ │ ├── AbstractDelegationTest.java │ │ ├── ArrayTest.java │ │ ├── BalancedAbstractnessTest.java │ │ ├── BigDecimalTest.java │ │ ├── DontOverrideEqualsTest.java │ │ ├── EnumTest.java │ │ ├── ExtendedReflexivityTest.java │ │ ├── FloatAndDoubleTest.java │ │ ├── GenericTypesTest.java │ │ ├── InstanceofPatternMatchTest.java │ │ ├── InterfaceTest.java │ │ ├── JavaApiClassesTest.java │ │ ├── JavaCollectionSubclassTest.java │ │ ├── JavaxClassesTest.java │ │ ├── MapEntrySubclassTest.java │ │ ├── ModulesTest.java │ │ ├── MutableStateTest.java │ │ ├── NullFieldsTest.java │ │ ├── NullFieldsWithExceptionsTest.java │ │ ├── PrefabValuesForFieldInRecordTest.java │ │ ├── RecordsTest.java │ │ ├── SealedTypesRecursionTest.java │ │ ├── SealedTypesTest.java │ │ ├── ShadowingTest.java │ │ ├── SignatureTest.java │ │ ├── SignificantFieldsTest.java │ │ ├── StringTest.java │ │ ├── SyntheticFieldsTest.java │ │ ├── TransientFieldsTest.java │ │ └── TypeCheckTest.java │ ├── extra_features │ │ ├── AnnotationImmutableTest.java │ │ ├── AnnotationNonNullFieldsTest.java │ │ ├── AnnotationNonnullEclipseTest.java │ │ ├── AnnotationNonnullTest.java │ │ ├── AnnotationNullMarkedTest.java │ │ ├── AnnotationParametersAreNonnullByDefaultTest.java │ │ ├── AnnotationsIgnoreTest.java │ │ ├── CachedHashCodeTest.java │ │ ├── GetClassInEqualityComparisonTest.java │ │ ├── GetClassTest.java │ │ ├── JakartaEntityTest.java │ │ ├── JakartaIdTest.java │ │ ├── JakartaLazyEntityTest.java │ │ ├── JpaEntityTest.java │ │ ├── JpaIdTest.java │ │ ├── JpaLazyEntityTest.java │ │ ├── LombokLazyEqualsAndHashcodeTest.java │ │ ├── OptionalDependencySanityTest.java │ │ ├── RelaxedEqualsPreconditionTest.java │ │ ├── RelaxedEqualsTest.java │ │ ├── SetModeTest.java │ │ ├── SimpleEqualsVerifierTest.java │ │ ├── VersionedEntityTest.java │ │ ├── WarningsMixTest.java │ │ ├── nonnull │ │ │ ├── eclipse │ │ │ │ ├── NonnullEclipseOnPackage.java │ │ │ │ └── package-info.java │ │ │ ├── findbugs1x │ │ │ │ ├── custom │ │ │ │ │ ├── NonnullFindbugs1xCustomOnPackage.java │ │ │ │ │ ├── NonnullFindbugs1xWithCheckForNullOnPackage.java │ │ │ │ │ └── package-info.java │ │ │ │ └── javax │ │ │ │ │ ├── NonnullFindbugs1xJavaxOnPackage.java │ │ │ │ │ ├── NonnullFindbugs1xWithNullableOnPackage.java │ │ │ │ │ └── package-info.java │ │ │ ├── jspecify │ │ │ │ ├── NullMarkedOnPackage.java │ │ │ │ └── package-info.java │ │ │ ├── jsr305 │ │ │ │ ├── custom │ │ │ │ │ ├── NonnullJsr305CustomOnPackage.java │ │ │ │ │ ├── NonnullJsr305WithNullableOnPackage.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── inapplicable │ │ │ │ │ ├── NonnullJsr305InapplicableOnPackage.java │ │ │ │ │ └── package-info.java │ │ │ │ ├── javax │ │ │ │ │ ├── NonnullJsr305JavaxOnPackage.java │ │ │ │ │ ├── NonnullJsr305WithCheckForNullOnPackage.java │ │ │ │ │ └── package-info.java │ │ │ │ └── parametersarenonnullbydefault │ │ │ │ │ ├── ParametersAreNonnullByDefaultOnPackage.java │ │ │ │ │ └── package-info.java │ │ │ └── springframework │ │ │ │ ├── NonNullFieldsOnPackage.java │ │ │ │ └── package-info.java │ │ └── simple_package │ │ │ ├── SimplePoint.java │ │ │ └── subpackage │ │ │ └── SimplePoint.java │ ├── inheritance │ │ ├── AbstractHierarchyTest.java │ │ ├── FinalityTest.java │ │ ├── SubclassTest.java │ │ └── SuperclassTest.java │ └── operational │ │ ├── ConfiguredEqualsVerifierMultipleTest.java │ │ ├── ConfiguredEqualsVerifierSingleTest.java │ │ ├── ForExamplesPreconditionsTest.java │ │ ├── ForExamplesTest.java │ │ ├── ModuleTest.java │ │ ├── MultipleTypeEqualsVerifierTest.java │ │ ├── OriginalStateTest.java │ │ ├── OutputTest.java │ │ ├── RecursionTest.java │ │ ├── ReportTest.java │ │ ├── SignedJarTest.java │ │ ├── WithGenericPrefabValuesTest.java │ │ ├── WithPrefabValuesForFieldTest.java │ │ └── WithPrefabValuesTest.java │ └── testhelpers │ └── packages │ ├── correct │ ├── A.java │ ├── B.java │ ├── C.java │ └── subpackage │ │ ├── A.java │ │ ├── B.java │ │ └── subpackage │ │ ├── A.java │ │ ├── B.java │ │ └── D.java │ ├── somerecursive │ ├── Nonrecursive.java │ ├── RecursiveA.java │ └── RecursiveB.java │ ├── subclasses │ ├── SubA.java │ ├── SubI.java │ ├── SuperA.java │ └── SuperI.java │ └── twoincorrect │ ├── IncorrectM.java │ ├── IncorrectN.java │ ├── X.java │ ├── Y.java │ ├── Z.java │ └── subpackage │ ├── IncorrectO.java │ └── IncorrectP.java ├── equalsverifier-testhelpers ├── pom.xml └── src │ └── main │ └── java │ └── nl │ └── jqno │ └── equalsverifier_testhelpers │ ├── ExpectedException.java │ ├── Util.java │ ├── annotations │ ├── AnnotationWithAnnotation.java │ ├── AnnotationWithValues.java │ ├── DefaultNonnullCustom.java │ ├── DefaultNonnullInapplicable.java │ ├── DefaultNonnullJavax.java │ ├── DifficultAnnotation.java │ ├── Embeddable.java │ ├── Entity.java │ ├── FieldAnnotationClassRetention.java │ ├── FieldAnnotationDoesntInherit.java │ ├── FieldAnnotationInherits.java │ ├── FieldAnnotationRuntimeRetention.java │ ├── Id.java │ ├── Immutable.java │ ├── Inapplicable.java │ ├── MappedSuperclass.java │ ├── MethodAnnotationClassRetention.java │ ├── MethodAnnotationRuntimeRetention.java │ ├── NaturalId.java │ ├── NonNull.java │ ├── NotNull.java │ ├── PackageAnnotation.java │ ├── PostProcess.java │ ├── Transient.java │ ├── TypeAnnotationClassRetention.java │ ├── TypeAnnotationDoesntInherit.java │ ├── TypeAnnotationInherits.java │ ├── TypeAnnotationRuntimeRetention.java │ ├── TypeUseAnnotationClassRetention.java │ ├── TypeUseAnnotationDoesntInherit.java │ ├── TypeUseAnnotationInherits.java │ ├── TypeUseAnnotationRuntimeRetention.java │ ├── edu │ │ └── umd │ │ │ └── cs │ │ │ └── findbugs │ │ │ └── annotations │ │ │ └── DefaultAnnotation.java │ ├── javax │ │ ├── annotation │ │ │ └── Nonnull.java │ │ └── persistence │ │ │ ├── Basic.java │ │ │ ├── ElementCollection.java │ │ │ ├── Embeddable.java │ │ │ ├── EmbeddedId.java │ │ │ ├── Entity.java │ │ │ ├── FetchType.java │ │ │ ├── GeneratedValue.java │ │ │ ├── Id.java │ │ │ ├── ManyToMany.java │ │ │ ├── ManyToOne.java │ │ │ ├── MappedSuperclass.java │ │ │ ├── OneToMany.java │ │ │ ├── OneToOne.java │ │ │ └── Transient.java │ └── org │ │ ├── eclipse │ │ └── jdt │ │ │ └── annotation │ │ │ └── NonNullByDefault.java │ │ ├── hibernate │ │ └── annotations │ │ │ └── NaturalId.java │ │ ├── jspecify │ │ └── annotations │ │ │ ├── NullMarked.java │ │ │ └── Nullable.java │ │ └── springframework │ │ └── lang │ │ └── NonNullFields.java │ └── types │ ├── BlindlyEqualsColorPoint.java │ ├── BlindlyEqualsPoint.java │ ├── CanEqualColorPoint.java │ ├── CanEqualPoint.java │ ├── Color.java │ ├── ColorBlindColorPoint.java │ ├── ColorPoint3D.java │ ├── EqualSubclassForBlindlyEqualsPoint.java │ ├── EqualSubclassForCanEqualPoint.java │ ├── FinalMethodsPoint.java │ ├── FinalPoint.java │ ├── FinalPointContainer.java │ ├── GetClassPoint.java │ ├── ImmutableCanEqualPoint.java │ ├── Multiple.java │ ├── MutableCanEqualColorPoint.java │ ├── MutablePoint.java │ ├── Pair.java │ ├── Point.java │ ├── Point3D.java │ ├── PointContainer.java │ ├── PointContainerOpenForSubclassAttack.java │ ├── PreconditionTypeHelper.java │ ├── RecordPoint.java │ ├── RecursiveTypeHelper.java │ ├── SparseArrays.java │ ├── ThrowingInitializer.java │ └── TypeHelper.java ├── jreleaser.yml ├── pom.xml └── video.png /.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Reformats code according to google-java-format rules 2 | 263194cec89d64eeedfb667bfe59c3edd03c711f 3 | # Cleans up awkwardly formatterd code 4 | d698561e58fce0a498ccc9c43539046b5f9a6ddf 5 | # Prettier (initial run) 6 | a9aba4023da451dba32fcf7189348e3e063feaf4 7 | # Reformats after prettier-java update 8 | a3246612e0cb7173d4edd068eaa5bb017b0468da 9 | # Reformats according to Eclipse formatter 10 | 9d24f8eea0c4989649722d997d529bb25f7d0d4d 11 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | # make sure that script files are always in the correct format, no matter the OS. 4 | # i.e. Windows needs batch files to have CRLF, but shell scripts always need to be LF, which is especially important for WSL contexts. 5 | *.sh text eol=lf 6 | *.bat text eol=crlf 7 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Thank you for taking the time to contribute! 2 | 3 | All contributions are welcome: 4 | 5 | * You can ask a question on the [mailinglist](https://groups.google.com/forum/?fromgroups#!forum/equalsverifier) 6 | * You can [submit an issue or a feature request](https://github.com/jqno/equalsverifier/issues) 7 | * You can make a [pull request](https://github.com/jqno/equalsverifier/pulls) 8 | 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: 📜 Error messages explained 4 | url: https://jqno.nl/equalsverifier/errormessages/ 5 | about: You can check here if your problem already has a solution. 6 | - name: 📚 Manual 7 | url: https://jqno.nl/equalsverifier/manual/ 8 | about: You can check here how certain features are supposed to work. 9 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature-request.yml: -------------------------------------------------------------------------------- 1 | name: 💡 Feature request 2 | description: Suggest an idea to improve EqualsVerifier. 3 | title: '[Feature] ' 4 | body: 5 | 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thank you for taking the time to submit a feature request and trying to improve EqualsVerifier! I appreciate it! 10 | 11 | Before you continue, please take a moment to look at ["Submitting an issue"](http://jqno.nl/equalsverifier/submit-an-issue/). 12 | 13 | - type: textarea 14 | id: description 15 | attributes: 16 | label: Describe the feature 17 | description: A clear and concise description of what the feature should do. 18 | validations: 19 | required: true 20 | 21 | - type: textarea 22 | id: solution 23 | attributes: 24 | label: Describe the solution you'd like 25 | description: Please tell me how you prefer to see this feature implemented. 26 | 27 | - type: textarea 28 | id: alternatives 29 | attributes: 30 | label: Describe alternatives 31 | description: Are there alternative solutions you have considered? 32 | 33 | - type: textarea 34 | id: context 35 | attributes: 36 | label: Additional context 37 | description: Any other information you would like to share. 38 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Thank you for taking the time to submit a pull request and trying to improve EqualsVerifier! I appreciate it! 2 | 3 | Before you continue, please consider the following: 4 | 5 | - Is your PR small, such as a small bug fix with test, or a typo fix? Awesome, thank you! I'll probably merge it right away. 6 | - Is your PR large, such as a new feature? Please consider [submitting a feature request](https://github.com/jqno/equalsverifier/issues/new) first, so we can discuss what you're about to contribute. Perhaps a different approach fits better with EqualsVerifier's code base, or maybe a similar feature already exists. I would feel really bad if you spent all that effort on a PR if it's not a good fit for the project. 7 | 8 | # What problem does this pull request solve? 9 | 10 | # What alternatives did you consider? 11 | 12 | # Please provide any additional information below 13 | 14 | # NOTE 15 | 16 | - Please run `mvn spotless:apply` to format the code before opening a PR. Otherwise, GitHub Actions will complain at you 😉. 17 | - Mutation tests will be run by [PITest](https://pitest.org/) after opening the PR. It will post comments in the PR for each issue found. Please take a look and fix what makes sense, but don't worry about the ones that don't. 18 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "maven" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | groups: 8 | dependencies: 9 | patterns: 10 | - "*" 11 | - package-ecosystem: "github-actions" 12 | directory: "/" 13 | schedule: 14 | interval: "weekly" 15 | groups: 16 | dependencies: 17 | patterns: 18 | - "*" 19 | -------------------------------------------------------------------------------- /.github/scripts/next-version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Determines the next version of EqualsVerifier. 4 | # If the version was x.y, the new version will be x.y.1-SNAPSHOT 5 | # If the version was x.y.z, the new version will be x.y.(z+1)-SNAPSHOT 6 | 7 | if [ "$#" -ne 1 ]; then 8 | echo "Usage: $0 " 9 | exit 1 10 | fi 11 | 12 | version="$1" 13 | IFS='.' read -ra ADDR <<< "$version" 14 | 15 | if [ ${#ADDR[@]} -eq 2 ]; then 16 | echo "$version.1-SNAPSHOT" 17 | elif [ ${#ADDR[@]} -eq 3 ]; then 18 | (( ADDR[2]++ )) 19 | echo "${ADDR[0]}.${ADDR[1]}.${ADDR[2]}-SNAPSHOT" 20 | else 21 | echo "Error: Version format not supported." 22 | exit 1 23 | fi 24 | 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | pom.xml.versionsBackup 2 | dependency-reduced-pom.xml 3 | equalsverifier-release-verify/src/test/resources 4 | 5 | .project 6 | .classpath 7 | .settings 8 | bin 9 | target 10 | .DS_Store 11 | kls_database.db 12 | 13 | # IntelliJ files 14 | .idea 15 | *.iml 16 | 17 | # JReleaser 18 | trace.log 19 | out/ 20 | jreleaser-cli.jar 21 | JRELEASER_VERSION 22 | -------------------------------------------------------------------------------- /arcmutate-licence.txt: -------------------------------------------------------------------------------- 1 | #Licence file for pitest extensions 2 | #Wed Nov 30 14:44:36 GMT 2022 3 | expires=30/11/2027 4 | keyVersion=1 5 | signature=PUSWQ1MN3Fn+N4tCxnK+3jHSj1Mlrvve3VTIrmjF1hkGS+y1v05GX3YbHhwuIL6WUMMhOuV/+cyIbcnGZb4AeowyM7VbwZhrfmrxQ+KWokGO9ZcFyWXJ8zl/cLzHDibmFx+WDEUToBHP/NgED7X36HjE1UqBlqeAaW2zwJx117I\= 6 | packages=nl.jqno.equalsverifier.* 7 | type=OSSS 8 | -------------------------------------------------------------------------------- /build/eclipse-formatter-config.importorder: -------------------------------------------------------------------------------- 1 | #Organize Import Order 2 | #Mon Dec 09 20:14:26 CET 2024 3 | 0=\# 4 | 1=java 5 | 2= 6 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _site 2 | .sass-cache 3 | .jekyll-cache 4 | .jekyll-metadata 5 | vendor 6 | -------------------------------------------------------------------------------- /docs/.notags: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/docs/.notags -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | --- 2 | permalink: /404.html 3 | layout: default 4 | --- 5 | 6 | 19 | 20 |
21 |

404

22 | 23 |

Page not found :(

24 |

The requested page could not be found.

25 |
26 | -------------------------------------------------------------------------------- /docs/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jekyll/jekyll:4.0 2 | 3 | COPY Gemfile* /tmp/ 4 | WORKDIR /tmp 5 | RUN touch Gemfile.lock \ 6 | && chmod a+w Gemfile.lock \ 7 | && bundle install 8 | 9 | RUN mkdir /workdir 10 | WORKDIR /workdir 11 | 12 | ENTRYPOINT ["jekyll"] 13 | -------------------------------------------------------------------------------- /docs/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | group :jekyll_plugins do 4 | gem "github-pages" 5 | gem "jekyll-include-cache" 6 | gem "webrick" 7 | end 8 | 9 | -------------------------------------------------------------------------------- /docs/_data/navigation.yml: -------------------------------------------------------------------------------- 1 | # main links 2 | main: 3 | - title: "/" 4 | url: https://jqno.nl 5 | - title: "Blog" 6 | url: https://jqno.nl/blog 7 | - title: "Talks" 8 | url: https://jqno.nl/talks 9 | - title: "EqualsVerifier" 10 | url: / 11 | -------------------------------------------------------------------------------- /docs/_errormessages/abstract-delegation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Abstract delegation 3 | --- 4 | Abstract delegation: Foo's equals method delegates to an abstract method 5 | Abstract delegation: Foo's hashCode method delegates to an abstract method 6 | 7 | This error can occur when the class under test, one of its fields, or its superclass, is abstract, and their `equals` or `hashCode` method calls an abstract method. 8 | 9 | EqualsVerifier creates instances of the class under test and its superclass and repeatedly calls their `equals` and `hashCode` methods. However, it can't create implementations of abstract methods. The "Abstract delegation" error therefore occurs when calling `equals` or `hashCode` would throw an `AbstractMethodError`. 10 | 11 | If one of the fields has an abstract type, the error can be avoided by calling `withPrefabValues` for that type. For other cases, there is currently no solution. Try rewriting the class so that `equals` and `hashCode` can use fields, instead of the abstract method. 12 | 13 | Note that, from version 1.1.4, EqualsVerifier includes the name of the abstract method that caused the error in its error message. 14 | 15 | -------------------------------------------------------------------------------- /docs/_errormessages/class-or-field-is-not-accessible-jpms.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Class or field is not accessible via the Java Module System" 3 | --- 4 | The class is not accessible via the Java Module system. 5 | Consider opening the module that contains it. 6 | 7 |
8 | 9 | Field foo of type Bar is not accessible via the Java Module System. 10 | Consider opening the module that contains it, or add prefab values for type Bar. 11 | 12 | Either the class that EqualsVerifier is testing, or one of its fields, cannot be accessed due to restrictions from the Java Platform Module System. 13 | 14 | If it's the class that EqualsVerifier is testing, you must modify your `module-info.java` such that the package containing the class, is accessible for reflection via the `open` keyword. 15 | 16 | If it's one of the fields in the class, you can either modify your `module-info.java` as above, or add prefab values for the given type: 17 | 18 | 19 | {% highlight java %} 20 | EqualsVerifier.forClass(TheClassThatImTesting.class) 21 | .withPrefabValues(Bar.class, new Bar(1), new Bar(2)) 22 | .verify(); 23 | {% endhighlight %} 24 | 25 | See also the [section in the manual](/equalsverifier/manual/jpms) about modules. 26 | -------------------------------------------------------------------------------- /docs/_errormessages/float-equals-doesnt-use-floatcompare-for-field-foo.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Float: equals doesn't use Float.compare for field foo" 3 | --- 4 | See the answer for the similar problem with [Double](/equalsverifier/errormessages/double-equals-doesnt-use-doublecompare-for-field-foo). 5 | -------------------------------------------------------------------------------- /docs/_errormessages/noclassdeffounderror.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "NoClassDefFoundError" 3 | --- 4 | java.lang.AssertionError: java.lang.NoClassDefFoundError: net/sf/cglib/asm/FieldVisitor 5 | 6 | _Note_: This applies to versions of EqualsVerifier prior to version 1.5.1. As of version 1.5, EqualsVerifier is shipped as an "uber jar", which means it does not pull in any of its own dependencies anymore, and therefore won't conflict with different versions of these dependencies that may be on your classpath. 7 | 8 | If you get this error message, then you probably have a transitive dependency problem with cglib. EqualsVerifier requires version 2.2, but other libraries may depend on earlier versions. If their dependency happens to be resolved before EqualsVerifier's, the wrong version of cglib will be loaded on your classpath. 9 | 10 | To fix this, make sure you have cglib 2.2. If you use Maven, add the following lines to your pom: 11 | 12 | {% highlight xml %} 13 | 14 | 15 | 16 | cglib 17 | cglib-nodep 18 | 2.2 19 | 20 | 21 | 22 | {% endhighlight %} 23 | 24 | Also, make sure that you use cglib-nodep, instead of 'vanilla' cglib! 25 | -------------------------------------------------------------------------------- /docs/_errormessages/precondition-two-objects-are-equal-to-each-other.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Precondition: two objects are equal to each other" 3 | --- 4 | This issue was solved in EqualsVerifier 2.0. If you haven't [upgraded](/equalsverifier/migration1to2) yet, please do so if you can! If not, continue reading. 5 | 6 | This happens when two instances of the type under test, whose fields have different values, are still equal to each other. This usually happens when none of the type's fields influences the result of the call to `equals`. 7 | 8 | The main example of this situation occurs in singleton objects. EqualsVerifier cannot (and should not) be used to test singletons; by their very nature, there should be one and only one instance of a singleton in the system, whereas `equals` is only useful when two or more instances are around. In other words, there is no point in testing `equals` on a singleton. 9 | -------------------------------------------------------------------------------- /docs/_errormessages/redefined-superclass-object-should-not-equal-superclass-instance.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Redefined superclass: object should not equal superclass instance" 3 | --- 4 | This happens when `.withRedefinedSuperclass()` is called, but calling `superclass.equals(classUnderTest)` or `classUnderTest.equals(superclass)` is true. If the superclass and the class under test both override `equals`, and an instance of one is allowed to be equal to an instance of the other, there is no way to satisfy both the symmetry and transitivity requirements of the equals contract. 5 | 6 | There are two ways to fix this. Either override `equals` in the class under test only, not in the superclass; or make sure an instance of the class under test can never be equal to an instance of the superclass by using the `canEqual` style of `equals` method definition. Note that the latter option is quite complex. For more information, read [this article](http://www.artima.com/lejava/articles/equality.html), Pitfall #4. 7 | -------------------------------------------------------------------------------- /docs/_errormessages/significant-fields-equals-does-not-use-foo-or-it-is-stateless.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Significant fields: equals does not use foo, or it is stateless" 3 | --- 4 | The cause for this error message is usually that the `foo` field is not used in the class's `equals` contract: hence, "equals does not use foo". 5 | 6 | In this case, the error can be fixed by simply including `foo` in your `equals` and `hashCode` methods; or if this is intentional, you can suppress `Warning.ALL_FIELDS_SHOULD_BE_USED` or call `.withIgnoredFields`. 7 | 8 | This error message can also occur when `foo` is included, but it is of a type with no state. A stateless type is a type that has no fields (or derives its `equals` method directly from `Object` without overriding it.) In this case, the only way to make the error go away is to suppress `Warning.ALL_FIELDS_SHOULD_BE_USED` or to call `.withIgnoredFields`. 9 | 10 | See also the chapter on [ignoring fields](/equalsverifier/manual/ignoring-fields) in the manual. 11 | -------------------------------------------------------------------------------- /docs/_errormessages/subclass-equals-is-not-final.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Subclass: equals is not final" 3 | --- 4 | Subclass: equals is not final. 5 | Make your class or your equals method final, or supply an instance of a redefined subclass using withRedefinedSubclass if equals cannot be final. 6 | 7 | There are three ways to solve this error, in order of decreasing preference: 8 | 9 | * Make the `equals` method (or even the whole class) final. 10 | 11 | * If you intend your `equals` method to be overridden, and you also want subclasses to add state that needs to be included in the contract, you have to use `withRedefinedSubclass`, as seen in the example below. If you decide to go down this path, I recommend reading the manual page about [inheritance](/equalsverifier/manual/inheritance). 12 | 13 | {% highlight java %} 14 | EqualsVerifier.forClass(Foo.class) 15 | .withRedefinedSubclass(SomeSubclass.class) 16 | .verify(); 17 | {% endhighlight %} 18 | 19 | * As a last resort, use `.suppress(Warning.STRICT_INHERITANCE)` to suppress the error message. 20 | -------------------------------------------------------------------------------- /docs/_errormessages/transient-field.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Transient field 3 | --- 4 | Transient field foo should not be included in equals/hashCode contract 5 | 6 | This error message shows up if you include a transient field in `equals` or `hashCode`. The purpose of transient fields is that [they aren't part of the persisted state of an object](https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-8.3.1.3). Therefore, they shouldn't be part of `equals` either. 7 | 8 | This applies to fields marked with Java's `transient` keyword, and fields annotated with the JPA `@Transient` annotations. 9 | 10 | If, for whatever reason, you _do_ need to include a transient field in `equals` or `hashCode`, you can suppress `Warning.TRANSIENT_FIELDS` like this: 11 | 12 | {% highlight java %} 13 | EqualsVerifier.forClass(Foo.class) 14 | .suppress(Warning.TRANSIENT_FIELDS) 15 | .verify(); 16 | {% endhighlight %} 17 | -------------------------------------------------------------------------------- /docs/_errormessages/unable-to-make-field-accessible.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Unable to make field foo accessible: module bar does not "opens bar" to baz' 3 | --- 4 | This error message occurs in older versions of EqualsVerifier. If you upgrade, the error message wil probably be replaced with "The class is not accessible via the Java Module system" or "Field foo of type Bar is not accessible via the Java Module system". If so, please check [that error message](/equalsverifier/errormessages/class-or-field-is-not-accessible-jpms) 5 | -------------------------------------------------------------------------------- /docs/_includes/good-equals: -------------------------------------------------------------------------------- 1 | * **Effective Java**, Third Edition, items 10 (_Obey the general contract when overriding `equals`_) and 11 (_Always override `hashCode` when you override `equals`_)
2 | _Addison-Wesley, 2018_
3 | by Joshua Bloch
4 | [[book](https://www.amazon.com/Effective-Java-Joshua-Bloch/dp/0134685997/ref=sr_1_1?crid=1716V3KOOYIFP&keywords=effective+java&qid=1700062938&sprefix=effective+%2Caps%2C368&sr=8-1)] 5 | * **How to Write an Equality Method in Java**
6 | _1 June 2009_
7 | by Martin Odersky, Lex Spoon, and Bill Venners
8 | [[link](https://www.artima.com/articles/how-to-write-an-equality-method-in-java)] 9 | * **Not all equals methods are created equal**
10 | _7 November 2017_
11 | by Jan Ouwens
12 | [[video](https://www.youtube.com/watch?v=pNJ_O10XaoM)] 13 | * **Optimizing your equals() methods with Pattern Matching** - JEP Cafe #21
14 | _9 November 2023_
15 | by José Paumard
16 | [[video](https://www.youtube.com/watch?v=kuzjX_efuDs)] 17 | -------------------------------------------------------------------------------- /docs/_includes/maven: -------------------------------------------------------------------------------- 1 | {% highlight xml %} 2 | 3 | nl.jqno.equalsverifier 4 | equalsverifier 5 | 4.0 6 | test 7 | 8 | {% endhighlight %} 9 | 10 | or, for a 'fat' jar with no transitive dependencies: 11 | 12 | {% highlight xml %} 13 | 14 | nl.jqno.equalsverifier 15 | equalsverifier-nodep 16 | 4.0 17 | test 18 | 19 | {% endhighlight %} 20 | -------------------------------------------------------------------------------- /docs/_pages/changelog.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Changelog 3 | permalink: /changelog/ 4 | --- 5 | The changelog has moved! 6 | 7 | It's now in the [CHANGELOG.md](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md) file on GitHub. 8 | -------------------------------------------------------------------------------- /docs/_pages/inspiration.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Inspiration 3 | permalink: /inspiration/ 4 | --- 5 | The verifications are inspired by: 6 | 7 | * _Effective Java, Second Edition_ by Joshua Bloch, Addison-Wesley, 2008: Items 8 (_Obey the general contract when overriding `equals`_) and 9 (_Always override `hashCode` when you override `equals`_). 8 | * _Programming in Scala_ by Martin Odersky, Lex Spoon and Bill Venners, Artima Press, 2008: Chapter 28 (_Object equality_) / Second Edition, 2011: Chapter 30 (_Object equality_). A Java-centric version of this chapter can be found online [here](http://www.artima.com/lejava/articles/equality.html). 9 | * _JUnit Recipes_ by J.B. Rainsberger, Manning, 2005: Appendix B.2 (_Strangeness and transitivity_). 10 | * _How Do I Correctly Implement the equals() Method?_ by Tal Cohen, Dr. Dobb's Journal, May 2002. Read the [article](http://www.ddj.com/java/184405053) and Cohen's [follow-up](http://tal.forum2.org/equals). 11 | 12 | And of course GSBase's `EqualsTester` by Mike Bowler, Gargoyle Software, which I think is pretty good, but lacking with respect to inheritance. Also, it requires that examples be given, while EqualsVerifier can auto-generate them in most cases (which, of course, is way cool). You can find it on [SourceForge](http://gsbase.sourceforge.net/index.html). 13 | 14 | -------------------------------------------------------------------------------- /docs/_pages/manual.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Manual 3 | permalink: /manual/ 4 | --- 5 | These pages will quickly get you up and running with EqualsVerifier, and help you configure it in situations where the default behaviour is too strict. 6 | 7 | * [Why, what, how?](/equalsverifier/manual/why-what-how) 8 | * [Getting started](/equalsverifier/manual/getting-started) 9 | * [What does a good equals method look like?](/equalsverifier/manual/good-equals) 10 | * [Making things final](/equalsverifier/manual/final) 11 | * [Immutability](/equalsverifier/manual/immutability) 12 | * [instanceof or getClass()](/equalsverifier/manual/instanceof-or-getclass) 13 | * [Dealing with null](/equalsverifier/manual/null) 14 | * [Ignoring fields](/equalsverifier/manual/ignoring-fields) 15 | * [Testing several classes at once](/equalsverifier/manual/several-classes-at-once) 16 | * [Handling inheritance](/equalsverifier/manual/inheritance) 17 | * [JPA entities](/equalsverifier/manual/jpa-entities) 18 | * [Cached hashCodes](/equalsverifier/manual/caching-hashcodes) 19 | * [Relaxed equality](/equalsverifier/manual/relaxed-equality) 20 | * [Dealing with legacy systems](/equalsverifier/manual/legacy-systems) 21 | * [The Java Platform Module System](/equalsverifier/manual/jpms) 22 | * [What are these prefab values?](/equalsverifier/manual/prefab-values) 23 | * [Additional resources](/equalsverifier/resources) 24 | -------------------------------------------------------------------------------- /docs/_pages/migration2to3.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Migration guide 2 to 3 3 | permalink: /migration2to3/ 4 | --- 5 | When migrating from EqualsVerifier 2 to 3, there are a few things you should be aware of. (See also the [changelog](/equalsverifier/changelog#3.x)). 6 | 7 | * EqualsVerifier 3 no longer supports Java 7. Don't upgrade if you're still using Java 7. 8 | * `Warning.ANNOTATION` has been removed, as it's no longer needed: EqualsVerifier can now handle any bytecode reading issues by itself. You can safely remove the warning; it won't affect your code or how the EqualsVerifier test is run. 9 | * The content and layout of error messages is slightly different. If you have tools that depend on this, make sure these still work. You could also consider using `EqualsVerifier#report()` instead of `EqualsVerifier#verify()`. 10 | * EqualsVerifier is now smarter when it comes to type erasure. In rare cases, a `ClassCastException` would be thrown by EqualsVerifier when it couldn't figure out the correct generic types. You can now fix those with `#withGenericPrefabValues()`. See [this page](/equalsverifier/errormessages/recursive-datastructure#generics) for more information. 11 | 12 | If you encounter any other problems, please let me know in the [issue tracker](https://github.com/jqno/equalsverifier/issues). 13 | -------------------------------------------------------------------------------- /docs/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | jekyll: 4 | build: 5 | context: . 6 | volumes: 7 | - ".:/workdir:Z" 8 | ports: 9 | - 4000:4000 10 | command: 'serve' 11 | -------------------------------------------------------------------------------- /docs/images/error-messages.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/docs/images/error-messages.webp -------------------------------------------------------------------------------- /docs/images/getting-started.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/docs/images/getting-started.webp -------------------------------------------------------------------------------- /docs/images/manual.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/docs/images/manual.webp -------------------------------------------------------------------------------- /docs/images/needless-constraints.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/docs/images/needless-constraints.png -------------------------------------------------------------------------------- /docs/images/resources.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/docs/images/resources.webp -------------------------------------------------------------------------------- /equalsverifier-21/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | nl.jqno.equalsverifier 7 | equalsverifier-parent 8 | 4.0.1-SNAPSHOT 9 | 10 | jar 11 | 12 | equalsverifier-21 13 | EqualsVerifier | JDK 21 14 | 15 | 16 | 21 17 | 18 | 19 | 20 | 21 | nl.jqno.equalsverifier 22 | equalsverifier-core 23 | ${project.version} 24 | 25 | 26 | org.junit.jupiter 27 | junit-jupiter 28 | ${version.junit-jupiter} 29 | test 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /equalsverifier-21/src/main/java/nl/jqno/equalsverifier/internal/versionspecific/SequencedCollectionsHelper.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.versionspecific; 2 | 3 | import static nl.jqno.equalsverifier.internal.instantiation.vintage.factories.Factories.collection; 4 | import static nl.jqno.equalsverifier.internal.instantiation.vintage.factories.Factories.map; 5 | 6 | import java.util.*; 7 | 8 | import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; 9 | 10 | public final class SequencedCollectionsHelper { 11 | 12 | private SequencedCollectionsHelper() {} 13 | 14 | public static void add(FactoryCache factoryCache) { 15 | factoryCache.put(SequencedCollection.class, collection(ArrayList::new)); 16 | factoryCache.put(SequencedSet.class, collection(LinkedHashSet::new)); 17 | factoryCache.put(SequencedMap.class, map(LinkedHashMap::new)); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /equalsverifier-21/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/RecordPatternMatchTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extended_contract; 2 | 3 | import java.util.Objects; 4 | 5 | import nl.jqno.equalsverifier.EqualsVerifier; 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class RecordPatternMatchTest { 9 | 10 | @Test 11 | void succeed_whenEqualsUsesInstanceofPatternMatch() { 12 | EqualsVerifier.forClass(Point.class).verify(); 13 | } 14 | 15 | record Point(int x, int y) { 16 | @Override 17 | public boolean equals(Object obj) { 18 | return (this == obj || (obj instanceof Point(int otherX, int otherY) && x == otherX && y == otherY)); 19 | } 20 | 21 | @Override 22 | public int hashCode() { 23 | return Objects.hash(x, y); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Defines EqualsVerifier's needs in the modular world. 3 | * 4 | * @since 4.0 5 | */ 6 | // When making changes to this file, make sure they are 7 | // reflected in equalsverifier-release-nodep/../module-info.java! 8 | module nl.jqno.equalsverifier { 9 | exports nl.jqno.equalsverifier; 10 | exports nl.jqno.equalsverifier.api; 11 | 12 | // Direct dependencies 13 | requires transitive net.bytebuddy; 14 | requires org.objenesis; 15 | 16 | // Optional dependencies 17 | requires static org.mockito; 18 | 19 | // Built-in prefab values 20 | requires static java.desktop; 21 | requires static java.naming; 22 | requires static java.rmi; 23 | requires static java.sql; 24 | } 25 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/CheckReturnValue.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * Allows tooling to discover if you forgot to call `#verify()`. 7 | * 8 | * @since 3.18 9 | */ 10 | @Target({ ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.PACKAGE, ElementType.TYPE }) 11 | @Retention(RetentionPolicy.CLASS) 12 | public @interface CheckReturnValue {} 13 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/Mode.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier; 2 | 3 | import nl.jqno.equalsverifier.internal.ModeInstance; 4 | 5 | /** 6 | * Provides a number of modes that influence how {@code EqualsVerifier} operates. 7 | * 8 | * @since 4.0 9 | */ 10 | public sealed interface Mode permits ModeInstance { 11 | 12 | /** 13 | * Signals that EqualsVerifier should not use Mockito, even if it's available on the classpath or modulepath. 14 | * 15 | * @return The skipMockito mode. 16 | * 17 | * @since 4.0 18 | */ 19 | public static Mode skipMockito() { 20 | return ModeInstance.SKIP_MOCKITO; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/ModeInstance.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal; 2 | 3 | import nl.jqno.equalsverifier.Mode; 4 | 5 | public final class ModeInstance implements Mode { 6 | 7 | private ModeInstance() {} 8 | 9 | public static final Mode SKIP_MOCKITO = new ModeInstance(); 10 | } 11 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/Checker.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.checkers; 2 | 3 | @FunctionalInterface 4 | public interface Checker { 5 | void check(); 6 | } 7 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/FieldInspector.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.checkers; 2 | 3 | import nl.jqno.equalsverifier.internal.checkers.fieldchecks.FieldCheck; 4 | import nl.jqno.equalsverifier.internal.reflection.FieldIterable; 5 | import nl.jqno.equalsverifier.internal.reflection.FieldProbe; 6 | 7 | public class FieldInspector { 8 | 9 | private final Class type; 10 | private final boolean isKotlin; 11 | 12 | public FieldInspector(Class type, boolean isKotlin) { 13 | this.type = type; 14 | this.isKotlin = isKotlin; 15 | } 16 | 17 | public void check(FieldCheck check) { 18 | FieldIterable it = isKotlin ? FieldIterable.ofKotlin(type) : FieldIterable.of(type); 19 | for (FieldProbe fieldProbe : it) { 20 | check.execute(fieldProbe); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/NullChecker.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.checkers; 2 | 3 | import nl.jqno.equalsverifier.Warning; 4 | import nl.jqno.equalsverifier.internal.checkers.fieldchecks.NullPointerExceptionFieldCheck; 5 | import nl.jqno.equalsverifier.internal.util.Context; 6 | 7 | public class NullChecker implements Checker { 8 | 9 | private final Context context; 10 | 11 | public NullChecker(Context context) { 12 | this.context = context; 13 | } 14 | 15 | @Override 16 | public void check() { 17 | if (context.getConfiguration().getWarningsToSuppress().contains(Warning.NULL_FIELDS)) { 18 | return; 19 | } 20 | 21 | var inspector = new FieldInspector<>(context.getType(), context.getConfiguration().isKotlin()); 22 | inspector.check(new NullPointerExceptionFieldCheck<>(context)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/FieldCheck.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.checkers.fieldchecks; 2 | 3 | import nl.jqno.equalsverifier.internal.reflection.FieldProbe; 4 | 5 | @FunctionalInterface 6 | public interface FieldCheck { 7 | void execute(FieldProbe fieldProbe); 8 | } 9 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/checkers/fieldchecks/SymmetryFieldCheck.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.checkers.fieldchecks; 2 | 3 | import static nl.jqno.equalsverifier.internal.util.Assert.assertTrue; 4 | 5 | import nl.jqno.equalsverifier.internal.instantiation.SubjectCreator; 6 | import nl.jqno.equalsverifier.internal.reflection.FieldProbe; 7 | import nl.jqno.equalsverifier.internal.util.Formatter; 8 | 9 | public class SymmetryFieldCheck implements FieldCheck { 10 | 11 | private final SubjectCreator subjectCreator; 12 | 13 | public SymmetryFieldCheck(SubjectCreator subjectCreator) { 14 | this.subjectCreator = subjectCreator; 15 | } 16 | 17 | @Override 18 | public void execute(FieldProbe fieldProbe) { 19 | T left = subjectCreator.plain(); 20 | T right = subjectCreator.plain(); 21 | T changedRight = subjectCreator.withFieldChanged(fieldProbe.getField()); 22 | 23 | checkSymmetry(left, right); 24 | checkSymmetry(left, changedRight); 25 | } 26 | 27 | private void checkSymmetry(T left, T right) { 28 | assertTrue( 29 | Formatter.of("Symmetry: objects are not symmetric:\n %%\nand\n %%", left, right), 30 | left.equals(right) == right.equals(left)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/AssertionException.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | import nl.jqno.equalsverifier.internal.util.Formatter; 4 | 5 | /** Signals that an EqualsVerfier assertion has failed. */ 6 | public class AssertionException extends MessagingException { 7 | 8 | public AssertionException(Formatter message) { 9 | super(message.format()); 10 | } 11 | 12 | public AssertionException(Formatter message, Throwable cause) { 13 | super(message.format(), cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/EqualsVerifierInternalBugException.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | /** Signals a bug in EqualsVerifier. */ 4 | public class EqualsVerifierInternalBugException extends RuntimeException { 5 | 6 | private static final String BUG = 7 | "This is a bug in EqualsVerifier. Please report this in the issue tracker at https://www.jqno.nl/equalsverifier"; 8 | 9 | public EqualsVerifierInternalBugException() { 10 | super(BUG); 11 | } 12 | 13 | public EqualsVerifierInternalBugException(String message) { 14 | super(BUG + "\n" + message); 15 | } 16 | 17 | public EqualsVerifierInternalBugException(Throwable cause) { 18 | super(BUG, cause); 19 | } 20 | 21 | public EqualsVerifierInternalBugException(String message, Throwable cause) { 22 | super(BUG + "\n" + message, cause); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/MessagingException.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | /** 4 | * Superclass for exceptions that exist only to send a message to the user when something goes wrong. These exceptions 5 | * do not need to be included as a cause in the final stack trace. If they have a cause, this cause will serve directly 6 | * as the cause for the final stack trace, instead of the exception itself. 7 | */ 8 | @SuppressWarnings("serial") 9 | public abstract class MessagingException extends RuntimeException { 10 | 11 | private final String description; 12 | 13 | public MessagingException() { 14 | this(null, null); 15 | } 16 | 17 | public MessagingException(String description) { 18 | this(description, null); 19 | } 20 | 21 | public MessagingException(String description, Throwable cause) { 22 | super(null, cause); 23 | this.description = description; 24 | } 25 | 26 | public String getDescription() { 27 | return description; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/MockitoException.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | import nl.jqno.equalsverifier.internal.util.Formatter; 4 | 5 | public class MockitoException extends MessagingException { 6 | public MockitoException(String fieldName, String typeName) { 7 | super(Formatter 8 | .of( 9 | """ 10 | Unable to use Mockito to mock field %% of type %%. 11 | Please provide a prefab value for this type, or use #set(Mode.skipMockito()) to skip using Mockito altogether.""", 12 | fieldName, 13 | typeName) 14 | .format()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/ModuleException.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | /** Signals that a class was inaccessible. */ 4 | public class ModuleException extends MessagingException { 5 | 6 | public ModuleException(String message, Throwable cause) { 7 | super(message, cause); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/NoValueException.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | /** Signals that no value could be provided for a given type. */ 4 | public class NoValueException extends MessagingException { 5 | 6 | public NoValueException(String description) { 7 | super(description); 8 | } 9 | 10 | public NoValueException(String description, Throwable cause) { 11 | super(description, cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/exceptions/ReflectionException.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | /** Signals that a reflection call went awry. */ 4 | public class ReflectionException extends RuntimeException { 5 | 6 | public ReflectionException(String message, Throwable cause) { 7 | super(message, cause); 8 | } 9 | 10 | public ReflectionException(String message) { 11 | super(message); 12 | } 13 | 14 | public ReflectionException(Throwable cause) { 15 | super(cause); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/ChainedValueProvider.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | import java.util.Optional; 6 | 7 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 8 | import nl.jqno.equalsverifier.internal.reflection.TypeTag; 9 | 10 | /** 11 | * Provider of prefabricated instances of classes, delegating to other ValueProviders in sequence. 12 | */ 13 | public class ChainedValueProvider implements ValueProvider { 14 | 15 | private final List providers; 16 | 17 | /** 18 | * Constructor. 19 | * 20 | * @param providers A list of ValueProviders that are checked in turn for a value. 21 | */ 22 | public ChainedValueProvider(ValueProvider... providers) { 23 | this.providers = Arrays.asList(providers); 24 | } 25 | 26 | /** {@inheritDoc} */ 27 | @Override 28 | public Optional> provide(TypeTag tag, String fieldName) { 29 | return providers 30 | .stream() 31 | .map(vp -> vp.provide(tag, fieldName)) 32 | .filter(Optional::isPresent) 33 | .findFirst() 34 | .orElse(Optional.empty()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/JavaIoValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.io.File; 4 | import java.io.PrintStream; 5 | import java.util.Optional; 6 | 7 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 8 | 9 | class JavaIoValueSupplier extends ValueSupplier { 10 | public JavaIoValueSupplier(Class type) { 11 | super(type); 12 | } 13 | 14 | @Override 15 | public Optional> get() { 16 | if (is(File.class)) { 17 | return val(new File(""), new File("/"), new File("")); 18 | } 19 | if (is(PrintStream.class)) { 20 | return val(System.out, System.err, System.out); 21 | } 22 | 23 | return Optional.empty(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/JavaMathValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.math.BigDecimal; 4 | import java.math.BigInteger; 5 | import java.util.Optional; 6 | 7 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 8 | 9 | class JavaMathValueSupplier extends ValueSupplier { 10 | public JavaMathValueSupplier(Class type) { 11 | super(type); 12 | } 13 | 14 | @Override 15 | public Optional> get() { 16 | if (is(BigDecimal.class)) { 17 | return val(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.ZERO); 18 | } 19 | if (is(BigInteger.class)) { 20 | return val(BigInteger.ZERO, BigInteger.ONE, BigInteger.ZERO); 21 | } 22 | 23 | return Optional.empty(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/JavaRmiValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.rmi.dgc.VMID; 4 | import java.rmi.server.UID; 5 | import java.util.Optional; 6 | 7 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 8 | 9 | class JavaRmiValueSupplier extends ValueSupplier { 10 | 11 | public JavaRmiValueSupplier(Class type) { 12 | super(type); 13 | } 14 | 15 | @Override 16 | public Optional> get() { 17 | if (is(VMID.class)) { 18 | VMID red = new VMID(); 19 | return val(red, new VMID(), red); 20 | } 21 | if (is(UID.class)) { 22 | UID red = new UID(); 23 | return val(red, new UID(), red); 24 | } 25 | 26 | return Optional.empty(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/JavaSqlValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.sql.*; 4 | import java.util.Optional; 5 | 6 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 7 | 8 | class JavaSqlValueSupplier extends ValueSupplier { 9 | public JavaSqlValueSupplier(Class type) { 10 | super(type); 11 | } 12 | 13 | @Override 14 | public Optional> get() { 15 | if (is(Date.class)) { 16 | return val(new Date(1337), new Date(42), new Date(1337)); 17 | } 18 | if (is(Time.class)) { 19 | return val(new Time(1337), new Time(42), new Time(1337)); 20 | } 21 | if (is(Timestamp.class)) { 22 | return val(new Timestamp(1337), new Timestamp(42), new Timestamp(1337)); 23 | } 24 | 25 | return Optional.empty(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/JavaTextValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.text.*; 4 | import java.util.Optional; 5 | 6 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 7 | 8 | class JavaTextValueSupplier extends ValueSupplier { 9 | public JavaTextValueSupplier(Class type) { 10 | super(type); 11 | } 12 | 13 | @Override 14 | public Optional> get() { 15 | if (is(DateFormat.class)) { 16 | return val(DateFormat.getTimeInstance(), DateFormat.getDateInstance(), DateFormat.getTimeInstance()); 17 | } 18 | if (is(DecimalFormat.class)) { 19 | return val(new DecimalFormat("x0.0"), new DecimalFormat("y0.0"), new DecimalFormat("x0.0")); 20 | } 21 | if (is(NumberFormat.class)) { 22 | return val(new DecimalFormat("x0.0"), new DecimalFormat("y0.0"), new DecimalFormat("x0.0")); 23 | } 24 | if (is(SimpleDateFormat.class)) { 25 | return val(new SimpleDateFormat("yMd"), new SimpleDateFormat("dMy"), new SimpleDateFormat("yMd")); 26 | } 27 | 28 | return Optional.empty(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/JavaxNamingValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.util.Optional; 4 | import javax.naming.Reference; 5 | 6 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 7 | 8 | class JavaxNamingValueSupplier extends ValueSupplier { 9 | 10 | public JavaxNamingValueSupplier(Class type) { 11 | super(type); 12 | } 13 | 14 | @Override 15 | public Optional> get() { 16 | if (is(Reference.class)) { 17 | return val(new Reference("one"), new Reference("two"), new Reference("one")); 18 | } 19 | 20 | return Optional.empty(); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/JavaxSwingValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.util.Optional; 4 | import javax.swing.tree.DefaultMutableTreeNode; 5 | 6 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 7 | 8 | class JavaxSwingValueSupplier extends ValueSupplier { 9 | 10 | public JavaxSwingValueSupplier(Class type) { 11 | super(type); 12 | } 13 | 14 | @Override 15 | public Optional> get() { 16 | if (is(DefaultMutableTreeNode.class)) { 17 | return val( 18 | new DefaultMutableTreeNode(), 19 | new DefaultMutableTreeNode(new Object()), 20 | new DefaultMutableTreeNode()); 21 | } 22 | 23 | return Optional.empty(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/OthersValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.beans.PropertyChangeSupport; 4 | import java.time.format.DateTimeFormatter; 5 | import java.util.Optional; 6 | import java.util.regex.Pattern; 7 | 8 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 9 | 10 | class OthersValueSupplier extends ValueSupplier { 11 | public OthersValueSupplier(Class type) { 12 | super(type); 13 | } 14 | 15 | @Override 16 | public Optional> get() { 17 | if (is(DateTimeFormatter.class)) { 18 | return val(DateTimeFormatter.ISO_TIME, DateTimeFormatter.ISO_DATE, DateTimeFormatter.ISO_TIME); 19 | } 20 | if (is(Pattern.class)) { 21 | return val(Pattern.compile("one"), Pattern.compile("two"), Pattern.compile("one")); 22 | } 23 | if (is(PropertyChangeSupport.class)) { 24 | return val( 25 | new PropertyChangeSupport("this"), 26 | new PropertyChangeSupport("that"), 27 | new PropertyChangeSupport("this")); 28 | } 29 | 30 | return Optional.empty(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/prefab/ValueSupplier.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.prefab; 2 | 3 | import java.util.Optional; 4 | import java.util.function.Supplier; 5 | 6 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 7 | 8 | abstract class ValueSupplier implements Supplier>> { 9 | private final Class type; 10 | 11 | public ValueSupplier(Class type) { 12 | this.type = type; 13 | } 14 | 15 | @Override 16 | public abstract Optional> get(); 17 | 18 | protected boolean is(Class otherType) { 19 | return type.equals(otherType); 20 | } 21 | 22 | /* 23 | * T is an unknown type at compile-time, but the types of the three parameters are known at compile-time. The 24 | * compiler thinks these are not the same as T, even though we know they are. Therefore, we must trick the compiler 25 | * by introducing type parameter S and casting the values. 26 | */ 27 | @SuppressWarnings("unchecked") 28 | protected Optional> val(S red, S blue, S redCopy) { 29 | return Optional.of(new Tuple<>((T) red, (T) blue, (T) redCopy)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/factories/PrefabValueFactory.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.vintage.factories; 2 | 3 | import java.util.LinkedHashSet; 4 | 5 | import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; 6 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 7 | import nl.jqno.equalsverifier.internal.reflection.TypeTag; 8 | 9 | /** 10 | * Creates instances of generic types for use as prefab value. 11 | * 12 | * @param The type to instantiate. 13 | */ 14 | @FunctionalInterface 15 | public interface PrefabValueFactory { 16 | /** 17 | * Creates a tuple of two prefab values. 18 | * 19 | * @param tag The typetag of the type for which to create values. 20 | * @param valueProvider Repository for querying instances of generic types of the type tag. 21 | * @param typeStack A stack of {@link TypeTag}s that require tag in order to be created. Used for recursion 22 | * detection. 23 | * @return A "red" instance of {@code T}. 24 | */ 25 | @SuppressWarnings("NonApiType") // LinkedHashSet is needed for its stack properties. 26 | Tuple createValues(TypeTag tag, VintageValueProvider valueProvider, LinkedHashSet typeStack); 27 | } 28 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/instantiation/vintage/factories/SimpleFactory.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.vintage.factories; 2 | 3 | import java.util.LinkedHashSet; 4 | 5 | import nl.jqno.equalsverifier.internal.instantiation.vintage.VintageValueProvider; 6 | import nl.jqno.equalsverifier.internal.reflection.Tuple; 7 | import nl.jqno.equalsverifier.internal.reflection.TypeTag; 8 | 9 | /** 10 | * Implementation of {@link PrefabValueFactory} that holds on to two instances that have already been created. 11 | */ 12 | public class SimpleFactory implements PrefabValueFactory { 13 | 14 | private final Tuple tuple; 15 | 16 | public SimpleFactory(T red, T blue, T redCopy) { 17 | this.tuple = new Tuple<>(red, blue, redCopy); 18 | } 19 | 20 | @Override 21 | @SuppressWarnings("NonApiType") // LinkedHashSet is needed for its stack properties. 22 | public Tuple createValues(TypeTag tag, VintageValueProvider valueProvider, LinkedHashSet typeStack) { 23 | return tuple; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/FieldMutator.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.reflection; 2 | 3 | import static nl.jqno.equalsverifier.internal.util.Rethrow.rethrow; 4 | 5 | import java.lang.reflect.Field; 6 | 7 | /** 8 | * Allows for a field in an object reference to be set to another value. 9 | */ 10 | public class FieldMutator { 11 | 12 | private final FieldProbe probe; 13 | private final Field field; 14 | 15 | /** 16 | * Constructor. 17 | * 18 | * @param probe A field probe pointing to the field to mutate. 19 | */ 20 | public FieldMutator(FieldProbe probe) { 21 | this.probe = probe; 22 | this.field = probe.getField(); 23 | } 24 | 25 | /** 26 | * Assigns {@code newValue} to the current field in {@code object}. 27 | * 28 | * @param object The instance on which to re-assign the current field. 29 | * @param newValue The value to assign to the field. 30 | */ 31 | public void setNewValue(Object object, Object newValue) { 32 | rethrow(() -> { 33 | if (probe.canBeModifiedReflectively()) { 34 | field.setAccessible(true); 35 | field.set(object, newValue); 36 | } 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/ModuleProbe.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.reflection; 2 | 3 | public final class ModuleProbe { 4 | 5 | private ModuleProbe() {} 6 | 7 | public static boolean runsOnModulePath() { 8 | return ModuleLayer.boot().findModule("nl.jqno.equalsverifier").isPresent(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/reflection/Tuple.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.reflection; 2 | 3 | /** 4 | * Container for three values of the same type: a "red" one, a "blue" one, and a shallow copy of the "red" one. 5 | * 6 | * @param red The red value. 7 | * @param blue The blue value. 8 | * @param redCopy A shallow copy of the red value. 9 | * @param The assumed type of the values. 10 | */ 11 | public final record Tuple(T red, T blue, T redCopy) {} 12 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/ErrorMessage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.util; 2 | 3 | import nl.jqno.equalsverifier.internal.reflection.ModuleProbe; 4 | 5 | public final class ErrorMessage { 6 | 7 | private ErrorMessage() {} 8 | 9 | private static final String WEBSITE_URL = 10 | "For more information, go to: https://www.jqno.nl/equalsverifier/errormessages"; 11 | 12 | public static String suffix() { 13 | return Formatter 14 | .of( 15 | "%%\n(EqualsVerifier %%, JDK %% running on %%, on %%. Mockito: %%.)", 16 | WEBSITE_URL, 17 | ErrorMessage.class.getPackage().getImplementationVersion(), 18 | System.getProperty("java.version"), 19 | ModuleProbe.runsOnModulePath() ? "modulepath" : "classpath", 20 | System.getProperty("os.name"), 21 | ExternalLibs.isMockitoAvailable() ? "available" : "not available") 22 | .format(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/ExternalLibs.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.util; 2 | 3 | import nl.jqno.equalsverifier.internal.reflection.Util; 4 | 5 | public final class ExternalLibs { 6 | private ExternalLibs() {} 7 | 8 | public static boolean isMockitoAvailable() { 9 | return Util.classForName("org.mockito.Mockito") != null; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/FieldNameExtractor.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.util; 2 | 3 | import java.util.Collections; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import nl.jqno.equalsverifier.internal.reflection.FieldIterable; 8 | import nl.jqno.equalsverifier.internal.reflection.FieldProbe; 9 | 10 | public final class FieldNameExtractor { 11 | 12 | private FieldNameExtractor() {} 13 | 14 | public static Set extractFieldNames(Class type) { 15 | var actualFieldNames = new HashSet(); 16 | for (FieldProbe p : FieldIterable.of(type)) { 17 | String name = p.getName(); 18 | actualFieldNames.add(name); 19 | } 20 | 21 | return Collections.unmodifiableSet(actualFieldNames); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/util/FieldToPrefabValues.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.util; 2 | 3 | import nl.jqno.equalsverifier.api.SingleTypeEqualsVerifierApi; 4 | import nl.jqno.equalsverifier.internal.reflection.FieldIterable; 5 | import nl.jqno.equalsverifier.internal.reflection.FieldProbe; 6 | 7 | public final class FieldToPrefabValues { 8 | 9 | private FieldToPrefabValues() {} 10 | 11 | @SuppressWarnings("CheckReturnValue") 12 | public static void move(SingleTypeEqualsVerifierApi api, Class type, T red, T blue) { 13 | for (FieldProbe probe : FieldIterable.ofIgnoringStatic(type)) { 14 | Object fRed = probe.getValue(red); 15 | Object fBlue = probe.getValue(blue); 16 | api.withPrefabValuesForField(probe.getName(), fRed, fBlue); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /equalsverifier-core/src/main/java/nl/jqno/equalsverifier/internal/versionspecific/SequencedCollectionsHelper.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.versionspecific; 2 | 3 | import nl.jqno.equalsverifier.internal.instantiation.vintage.FactoryCache; 4 | 5 | public final class SequencedCollectionsHelper { 6 | 7 | private SequencedCollectionsHelper() {} 8 | 9 | public static void add(FactoryCache factoryCache) {} 10 | } 11 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/EqualsVerifierTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal; 2 | 3 | import static nl.jqno.equalsverifier_testhelpers.Util.coverThePrivateConstructor; 4 | 5 | import nl.jqno.equalsverifier.EqualsVerifier; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class EqualsVerifierTest { 9 | 10 | @Test 11 | void coverTheConstructor() { 12 | coverThePrivateConstructor(EqualsVerifier.class); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/PrefabValuesApiTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal; 2 | 3 | import static nl.jqno.equalsverifier_testhelpers.Util.coverThePrivateConstructor; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class PrefabValuesApiTest { 8 | 9 | @Test 10 | void coverTheConstructor() { 11 | coverThePrivateConstructor(PrefabValuesApi.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/exceptions/RecursionExceptionTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.exceptions; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.util.LinkedHashSet; 6 | 7 | import nl.jqno.equalsverifier.internal.reflection.TypeTag; 8 | import nl.jqno.equalsverifier_testhelpers.types.Point; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class RecursionExceptionTest { 12 | 13 | @Test 14 | void descriptionContainsAllTypes() { 15 | var stack = new LinkedHashSet(); 16 | stack.add(new TypeTag(String.class)); 17 | stack.add(new TypeTag(Point.class)); 18 | stack.add(new TypeTag(Object.class)); 19 | 20 | String message = new RecursionException(stack).getDescription(); 21 | 22 | for (TypeTag tag : stack) { 23 | assertThat(message).contains(tag.toString()); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/RecordInstanceCreatorTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import java.lang.reflect.Field; 6 | import java.util.Map; 7 | 8 | import nl.jqno.equalsverifier.internal.reflection.ClassProbe; 9 | import org.junit.jupiter.api.Test; 10 | import org.objenesis.ObjenesisStd; 11 | 12 | class RecordInstanceCreatorTest { 13 | 14 | @Test 15 | void instanceCreator() throws NoSuchFieldException { 16 | ClassProbe probe = ClassProbe.of(SomeRecord.class); 17 | var sut = new InstanceCreator(probe, new ObjenesisStd()); 18 | 19 | Field x = SomeRecord.class.getDeclaredField("x"); 20 | Field z = SomeRecord.class.getDeclaredField("z"); 21 | var values = Map.of(x, 42, z, "42"); 22 | 23 | SomeRecord actual = sut.instantiate(values); 24 | 25 | assertThat(actual.x).isEqualTo(42); 26 | assertThat(actual.y).isEqualTo(0); 27 | assertThat(actual.z).isEqualTo("42"); 28 | } 29 | 30 | record SomeRecord(int x, int y, String z) {} 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/factories/FactoriesTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.vintage.factories; 2 | 3 | import static nl.jqno.equalsverifier_testhelpers.Util.coverThePrivateConstructor; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class FactoriesTest { 8 | 9 | @Test 10 | void coverTheConstructor() { 11 | coverThePrivateConstructor(Factories.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/factories/SimpleFactoryTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.vintage.factories; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class SimpleFactoryTest { 8 | 9 | private final SimpleFactory factory = new SimpleFactory<>("red", "blue", new String("red")); 10 | 11 | @Test 12 | void createRed() { 13 | assertThat(factory.createValues(null, null, null).red()).isEqualTo("red"); 14 | } 15 | 16 | @Test 17 | void createBlue() { 18 | assertThat(factory.createValues(null, null, null).blue()).isEqualTo("blue"); 19 | } 20 | 21 | @Test 22 | void redCopy() { 23 | String redCopy = factory.createValues(null, null, null).redCopy(); 24 | assertThat(redCopy).isEqualTo("red").isNotSameAs("red"); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/instantiation/vintage/reflection/InPlaceObjectAccessorTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.instantiation.vintage.reflection; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import nl.jqno.equalsverifier_testhelpers.types.Point; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class InPlaceObjectAccessorTest { 9 | 10 | @Test 11 | void of() { 12 | Point p = new Point(1, 2); 13 | ObjectAccessor actual = ObjectAccessor.of(p); 14 | assertThat(actual instanceof InPlaceObjectAccessor).isTrue(); 15 | } 16 | 17 | @Test 18 | void get() { 19 | Object foo = new Object(); 20 | InPlaceObjectAccessor accessor = create(foo); 21 | assertThat(accessor.get()).isSameAs(foo); 22 | } 23 | 24 | @SuppressWarnings("unchecked") 25 | private InPlaceObjectAccessor create(T object) { 26 | return new InPlaceObjectAccessor(object, (Class) object.getClass()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/ClassProbeSealedTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.reflection; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class ClassProbeSealedTest { 8 | 9 | @Test 10 | void isNotSealed() { 11 | var probe = ClassProbe.of(SealedChild.class); 12 | assertThat(probe.isSealed()).isFalse(); 13 | } 14 | 15 | @Test 16 | void isSealed() { 17 | var probe = ClassProbe.of(SealedParent.class); 18 | assertThat(probe.isSealed()).isTrue(); 19 | } 20 | 21 | public abstract static sealed class SealedParent {} 22 | 23 | public static non-sealed class SealedChild extends SealedParent {} 24 | } 25 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/RecordInstantiatorTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.reflection; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.objenesis.ObjenesisStd; 7 | 8 | class RecordInstantiatorTest { 9 | 10 | @Test 11 | void instantiateRecord() { 12 | Instantiator instantiator = Instantiator.of(SimpleRecord.class, new ObjenesisStd()); 13 | Object simpleRecord = instantiator.instantiate(); 14 | assertThat(simpleRecord.getClass()).isEqualTo(SimpleRecord.class); 15 | } 16 | 17 | record SimpleRecord(int i) {} 18 | } 19 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/reflection/TupleTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.reflection; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import nl.jqno.equalsverifier.EqualsVerifier; 6 | import nl.jqno.equalsverifier.Warning; 7 | import org.junit.jupiter.api.Test; 8 | 9 | class TupleTest { 10 | 11 | private final Tuple tuple = new Tuple<>("red", "blue", new String("red")); 12 | 13 | @Test 14 | void equalsAndHashCode() { 15 | EqualsVerifier.forClass(Tuple.class).suppress(Warning.NULL_FIELDS).verify(); 16 | } 17 | 18 | @Test 19 | void redAndRedCopyInvariant() { 20 | assertThat(tuple.redCopy()).isEqualTo(tuple.red()).isNotSameAs(tuple.red()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/internal/util/ListBuildersTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.internal.util; 2 | 3 | import static nl.jqno.equalsverifier_testhelpers.Util.coverThePrivateConstructor; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | class ListBuildersTest { 8 | 9 | @Test 10 | void coverTheConstructor() { 11 | coverThePrivateConstructor(ListBuilders.class); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/annotated/AnnotatedPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.annotated; 2 | 3 | public class AnnotatedPackage {} 4 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/annotated/package-info.java: -------------------------------------------------------------------------------- 1 | /** Puts an annotation on a whole package. */ 2 | @PackageAnnotation 3 | package nl.jqno.equalsverifier.testhelpers.packages.annotated; 4 | 5 | import nl.jqno.equalsverifier_testhelpers.annotations.PackageAnnotation; 6 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/anonymous/A.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.anonymous; 2 | 3 | import java.util.function.Supplier; 4 | 5 | public final class A { 6 | 7 | private final int x; 8 | private final int y; 9 | 10 | public A(int x, int y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | 15 | @Override 16 | public boolean equals(Object obj) { 17 | if (!(obj instanceof A)) { 18 | return false; 19 | } 20 | A p = (A) obj; 21 | return p.x == x && p.y == y; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | return x + (31 * y); 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return getClass().getSimpleName() + ":" + x + "," + y; 32 | } 33 | 34 | @SuppressWarnings("UnusedAnonymousClass") 35 | public static void anonymousClass() { 36 | new Supplier() { 37 | @Override 38 | public String get() { 39 | return ""; 40 | } 41 | }; 42 | } 43 | 44 | public static void localClass() { 45 | @SuppressWarnings({ "unused", "UnusedNestedClass" }) 46 | class Local { 47 | 48 | int x; 49 | int y; 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/A.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct; 2 | 3 | public final class A { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public A(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof A)) { 16 | return false; 17 | } 18 | A p = (A) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/B.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct; 2 | 3 | public final class B { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public B(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof B)) { 16 | return false; 17 | } 18 | B p = (B) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/C.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct; 2 | 3 | public final class C { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public C(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof C)) { 16 | return false; 17 | } 18 | C p = (C) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/A.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage; 2 | 3 | public final class A { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public A(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof A)) { 16 | return false; 17 | } 18 | A p = (A) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/B.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage; 2 | 3 | public final class B { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public B(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof B)) { 16 | return false; 17 | } 18 | B p = (B) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/subpackage/A.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage; 2 | 3 | public final class A { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public A(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof A)) { 16 | return false; 17 | } 18 | A p = (A) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/subpackage/B.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage; 2 | 3 | public final class B { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public B(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof B)) { 16 | return false; 17 | } 18 | B p = (B) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/subpackage/D.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage; 2 | 3 | public final class D { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public D(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof D)) { 16 | return false; 17 | } 18 | D p = (D) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/somerecursive/Nonrecursive.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.somerecursive; 2 | 3 | public final class Nonrecursive { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public Nonrecursive(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof Nonrecursive)) { 16 | return false; 17 | } 18 | Nonrecursive p = (Nonrecursive) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/somerecursive/RecursiveA.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.somerecursive; 2 | 3 | import java.util.Objects; 4 | 5 | public final class RecursiveA { 6 | 7 | private final RecursiveB b; 8 | 9 | public RecursiveA(RecursiveB b) { 10 | this.b = b; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof RecursiveA)) { 16 | return false; 17 | } 18 | RecursiveA p = (RecursiveA) obj; 19 | return Objects.equals(b, p.b); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(b); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + b; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/somerecursive/RecursiveB.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.somerecursive; 2 | 3 | import java.util.Objects; 4 | 5 | public final class RecursiveB { 6 | 7 | private final RecursiveA a; 8 | 9 | public RecursiveB(RecursiveA a) { 10 | this.a = a; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof RecursiveB)) { 16 | return false; 17 | } 18 | RecursiveB p = (RecursiveB) obj; 19 | return Objects.equals(a, p.a); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(a); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + a; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubA1.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public final class SubA1 extends SuperA { 4 | 5 | private final int i; 6 | 7 | public SubA1(int i) { 8 | this.i = i; 9 | } 10 | 11 | @Override 12 | public boolean equals(Object obj) { 13 | if (!(obj instanceof SubA1)) { 14 | return false; 15 | } 16 | SubA1 other = (SubA1) obj; 17 | return i == other.i; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return 31 * i; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return getClass().getSimpleName() + ":" + i; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubA2.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | import java.util.Objects; 4 | 5 | public final class SubA2 extends SuperA { 6 | 7 | private final String s; 8 | 9 | public SubA2(String s) { 10 | this.s = s; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof SubA2)) { 16 | return false; 17 | } 18 | SubA2 other = (SubA2) obj; 19 | return Objects.equals(s, other.s); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(s); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + s; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubB1.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public final class SubB1 extends SuperB { 4 | 5 | private final int i; 6 | 7 | public SubB1(int i) { 8 | this.i = i; 9 | } 10 | 11 | @Override 12 | public boolean equals(Object obj) { 13 | if (!(obj instanceof SubB1)) { 14 | return false; 15 | } 16 | SubB1 other = (SubB1) obj; 17 | return i == other.i; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return 31 * i; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return getClass().getSimpleName() + ":" + i; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubB2.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | import java.util.Objects; 4 | 5 | public final class SubB2 extends SuperB { 6 | 7 | private final String s; 8 | 9 | public SubB2(String s) { 10 | this.s = s; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof SubB2)) { 16 | return false; 17 | } 18 | SubB2 other = (SubB2) obj; 19 | return Objects.equals(s, other.s); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(s); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + s; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubI1.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public interface SubI1 extends SuperI {} 4 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubI2.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | import java.util.Objects; 4 | 5 | public final class SubI2 implements SuperI { 6 | 7 | private final String s; 8 | 9 | public SubI2(String s) { 10 | this.s = s; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof SubI2)) { 16 | return false; 17 | } 18 | SubI2 other = (SubI2) obj; 19 | return Objects.equals(s, other.s); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(s); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + s; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SuperA.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public class SuperA {} 4 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SuperB.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public class SuperB {} 4 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SuperI.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public interface SuperI {} 4 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/subpackage/SubA3.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses.subpackage; 2 | 3 | import java.util.Objects; 4 | 5 | import nl.jqno.equalsverifier.testhelpers.packages.subclasses.SuperA; 6 | 7 | public final class SubA3 extends SuperA { 8 | 9 | private final String s; 10 | 11 | public SubA3(String s) { 12 | this.s = s; 13 | } 14 | 15 | @Override 16 | public boolean equals(Object obj) { 17 | if (!(obj instanceof SubA3)) { 18 | return false; 19 | } 20 | SubA3 other = (SubA3) obj; 21 | return Objects.equals(s, other.s); 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | return Objects.hash(s); 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return getClass().getSimpleName() + ":" + s; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /equalsverifier-core/src/test/resources/simplelogger.properties: -------------------------------------------------------------------------------- 1 | org.slf4j.simpleLogger.defaultLogLevel=warn 2 | -------------------------------------------------------------------------------- /equalsverifier-release-main/src/main/assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | main-jar 8 | 9 | jar 10 | 11 | false 12 | 13 | assemblies/assembly.xml 14 | 15 | 16 | 17 | true 18 | 19 | nl.jqno.equalsverifier:equalsverifier-core 20 | 21 | 22 | true 23 | false 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /equalsverifier-release-nodep/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module nl.jqno.equalsverifier { 2 | exports nl.jqno.equalsverifier; 3 | exports nl.jqno.equalsverifier.api; 4 | 5 | // Direct dependencies are shaded, 6 | // so don't need to be declared here. 7 | 8 | // Optional dependencies 9 | requires static org.mockito; 10 | 11 | // Built-in prefab values 12 | requires static java.desktop; 13 | requires static java.naming; 14 | requires static java.rmi; 15 | requires static java.sql; 16 | } 17 | -------------------------------------------------------------------------------- /equalsverifier-release-nodep/src/main/java/nl/jqno/equalsverifier/Placeholder.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier; 2 | 3 | // A file needs to exist in this package in order to be able to compile the module-info.java 4 | public class Placeholder {} 5 | -------------------------------------------------------------------------------- /equalsverifier-release-nodep/src/main/java/nl/jqno/equalsverifier/api/Placeholder.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.api; 2 | 3 | // A file needs to exist in this package in order to be able to compile the module-info.java 4 | public class Placeholder {} 5 | -------------------------------------------------------------------------------- /equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/MainJavadocJarTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.verify_release.jar; 2 | 3 | import static nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter.EV; 4 | 5 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter; 6 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarReader; 7 | import org.junit.jupiter.api.AfterAll; 8 | import org.junit.jupiter.api.BeforeAll; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class MainJavadocJarTest { 12 | 13 | private static final String FILENAME = "equalsverifier-main-javadoc.jar"; 14 | private static JarReader reader; 15 | private static JarAsserter jar; 16 | 17 | @BeforeAll 18 | static void setup() { 19 | reader = new JarReader(FILENAME); 20 | jar = new JarAsserter(reader); 21 | } 22 | 23 | @AfterAll 24 | static void clean() throws Exception { 25 | reader.close(); 26 | } 27 | 28 | @Test 29 | void presenceOfCoreFiles() { 30 | jar.assertPresenceOf("/index.html", "/nl.jqno.equalsverifier" + EV + "/EqualsVerifier.html"); 31 | } 32 | 33 | @Test 34 | void absenceOfNonExportedPackages() { 35 | jar.assertAbsenceOf("/nl.jqno.equalsverifier" + EV + "/internal"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/MainSourcesJarTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.verify_release.jar; 2 | 3 | import static nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter.EV; 4 | 5 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter; 6 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarReader; 7 | import org.junit.jupiter.api.AfterAll; 8 | import org.junit.jupiter.api.BeforeAll; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class MainSourcesJarTest { 12 | 13 | private static final String FILENAME = "equalsverifier-main-sources.jar"; 14 | private static JarReader reader; 15 | private static JarAsserter jar; 16 | 17 | @BeforeAll 18 | static void setup() { 19 | reader = new JarReader(FILENAME); 20 | jar = new JarAsserter(reader); 21 | } 22 | 23 | @AfterAll 24 | static void clean() throws Exception { 25 | reader.close(); 26 | } 27 | 28 | @Test 29 | void presenceOfCoreSources() { 30 | jar.assertPresenceOf(EV + "/EqualsVerifier.java"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/NodepJavadocJarTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.verify_release.jar; 2 | 3 | import static nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter.EV; 4 | 5 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter; 6 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarReader; 7 | import org.junit.jupiter.api.AfterAll; 8 | import org.junit.jupiter.api.BeforeAll; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class NodepJavadocJarTest { 12 | 13 | private static final String FILENAME = "equalsverifier-nodep-javadoc.jar"; 14 | private static JarReader reader; 15 | private static JarAsserter jar; 16 | 17 | @BeforeAll 18 | static void setup() { 19 | reader = new JarReader(FILENAME); 20 | jar = new JarAsserter(reader); 21 | } 22 | 23 | @AfterAll 24 | static void clean() throws Exception { 25 | reader.close(); 26 | } 27 | 28 | @Test 29 | void presenceOfCoreFiles() { 30 | jar.assertPresenceOf("/index.html", "/nl.jqno.equalsverifier" + EV + "/EqualsVerifier.html"); 31 | } 32 | 33 | @Test 34 | void absenceOfNonExportedPackages() { 35 | jar.assertAbsenceOf("/nl.jqno.equalsverifier" + EV + "/internal"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /equalsverifier-release-verify/src/test/java/nl/jqno/equalsverifier/verify_release/jar/NodepSourcesJarTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.verify_release.jar; 2 | 3 | import static nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter.EV; 4 | 5 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarAsserter; 6 | import nl.jqno.equalsverifier.verify_release.jar.helper.JarReader; 7 | import org.junit.jupiter.api.AfterAll; 8 | import org.junit.jupiter.api.BeforeAll; 9 | import org.junit.jupiter.api.Test; 10 | 11 | class NodepSourcesJarTest { 12 | 13 | private static final String FILENAME = "equalsverifier-nodep-sources.jar"; 14 | private static JarReader reader; 15 | private static JarAsserter jar; 16 | 17 | @BeforeAll 18 | static void setup() { 19 | reader = new JarReader(FILENAME); 20 | jar = new JarAsserter(reader); 21 | } 22 | 23 | @AfterAll 24 | static void clean() throws Exception { 25 | reader.close(); 26 | } 27 | 28 | @Test 29 | void presenceOfCoreSources() { 30 | jar.assertPresenceOf(EV + "/EqualsVerifier.java"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /equalsverifier-test-jpms/src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module equalsverifier.jpms { 2 | exports nl.jqno.equalsverifier.jpms.model; 3 | 4 | opens nl.jqno.equalsverifier.jpms.model; 5 | 6 | requires java.desktop; 7 | requires java.naming; 8 | requires java.rmi; 9 | requires java.sql; 10 | } 11 | -------------------------------------------------------------------------------- /equalsverifier-test-jpms/src/main/java/nl/jqno/equalsverifier/jpms/model/ClassPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.jpms.model; 2 | 3 | import java.util.Objects; 4 | 5 | public final class ClassPoint { 6 | 7 | private final int x; 8 | private final int y; 9 | 10 | public ClassPoint(int x, int y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | 15 | @Override 16 | public boolean equals(Object obj) { 17 | return obj instanceof ClassPoint other && x == other.x && y == other.y; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return Objects.hash(x, y); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /equalsverifier-test-jpms/src/main/java/nl/jqno/equalsverifier/jpms/model/ClassPointContainer.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.jpms.model; 2 | 3 | import java.util.Objects; 4 | 5 | public final class ClassPointContainer { 6 | private final ClassPoint cp; 7 | 8 | public ClassPointContainer(ClassPoint cp) { 9 | this.cp = cp; 10 | } 11 | 12 | @Override 13 | public boolean equals(Object obj) { 14 | return obj instanceof ClassPointContainer other && Objects.equals(cp, other.cp); 15 | } 16 | 17 | @Override 18 | public int hashCode() { 19 | return Objects.hash(cp); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /equalsverifier-test-jpms/src/main/java/nl/jqno/equalsverifier/jpms/model/NonFinal.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.jpms.model; 2 | 3 | import java.util.Objects; 4 | 5 | public class NonFinal { 6 | private final int i; 7 | 8 | public NonFinal(int i) { 9 | this.i = i; 10 | } 11 | 12 | @Override 13 | public final boolean equals(Object obj) { 14 | return obj instanceof NonFinal other && i == other.i; 15 | } 16 | 17 | @Override 18 | public final int hashCode() { 19 | return Objects.hash(i); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /equalsverifier-test-jpms/src/main/java/nl/jqno/equalsverifier/jpms/model/Records.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.jpms.model; 2 | 3 | public final class Records { 4 | public record RecordPoint(int x, int y) {} 5 | 6 | public record RecordPointContainer(RecordPoint rp) {} 7 | } 8 | -------------------------------------------------------------------------------- /equalsverifier-test-jpms/src/test/java/it/SanityTest.java: -------------------------------------------------------------------------------- 1 | package it; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class SanityTest { 8 | @Test 9 | void sanity() { 10 | assertThat(getClass().getModule()) 11 | .extracting(Module::isNamed, Module::getName) 12 | .containsExactly(true, "equalsverifier.jpms.test"); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /equalsverifier-test-jpms/src/test/java/module-info.java: -------------------------------------------------------------------------------- 1 | open module equalsverifier.jpms.test { 2 | requires equalsverifier.jpms; 3 | requires equalsverifier.testhelpers; 4 | requires nl.jqno.equalsverifier; 5 | 6 | requires org.junit.jupiter.api; 7 | requires org.assertj.core; 8 | } 9 | -------------------------------------------------------------------------------- /equalsverifier-test-kotlin/src/test/kotlin/nl/jqno/equalsverifier/kotlin/KotlinCompilerGeneratedAnnotationTest.kt: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.kotlin 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier 4 | import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache 5 | import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCacheBuilder 6 | import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations 7 | import org.assertj.core.api.Assertions.assertThat 8 | import org.junit.jupiter.api.Test 9 | 10 | class KotlinCompilerGeneratedAnnotationTest { 11 | 12 | val cache = AnnotationCache() 13 | val cacheBuilder = AnnotationCacheBuilder(SupportedAnnotations.values(), HashSet()) 14 | 15 | @Test 16 | fun `Kotlin classes are recognised as such`() { 17 | assertThat(checkAnnotationFor(KotlinClass::class.java)).isTrue() 18 | } 19 | 20 | @Test 21 | fun `Java classes are not recognised as Kotlin classes`() { 22 | assertThat(checkAnnotationFor(EqualsVerifier::class.java)).isFalse() 23 | } 24 | 25 | private fun checkAnnotationFor(type: Class<*>): Boolean { 26 | cacheBuilder.build(type, cache) 27 | return cache.hasClassAnnotation(type, SupportedAnnotations.KOTLIN) 28 | } 29 | } 30 | 31 | class KotlinClass 32 | -------------------------------------------------------------------------------- /equalsverifier-test-mockito/src/test/java/nl/jqno/equalsverifier/mockito/SanityTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.mockito; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | import static org.mockito.Mockito.mock; 5 | 6 | import nl.jqno.equalsverifier.EqualsVerifier; 7 | import nl.jqno.equalsverifier_testhelpers.ExpectedException; 8 | import nl.jqno.equalsverifier_testhelpers.types.GetClassPoint; 9 | import nl.jqno.equalsverifier_testhelpers.types.Point; 10 | import org.junit.jupiter.api.Test; 11 | 12 | public class SanityTest { 13 | @Test 14 | void twoMockitoPointsAreUnequal() { 15 | var a = mock(Point.class); 16 | var b = mock(Point.class); 17 | 18 | assertThat(a).isNotEqualTo(b); 19 | } 20 | 21 | @Test 22 | void incorrectEqualsIsStillDetected() { 23 | ExpectedException 24 | .when(() -> EqualsVerifier.forClass(GetClassPoint.class).verify()) 25 | .assertFailure() 26 | .assertMessageContains("Subclass:"); 27 | } 28 | 29 | @Test 30 | void mockitoIsReportedInErrorMessage() { 31 | ExpectedException 32 | .when(() -> EqualsVerifier.forClass(GetClassPoint.class).verify()) 33 | .assertFailure() 34 | .assertMessageContains("Mockito: available"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.1/equalsverifier-signedjar-test-0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.1/equalsverifier-signedjar-test-0.1.jar -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.1/equalsverifier-signedjar-test-0.1.jar.md5: -------------------------------------------------------------------------------- 1 | 8d1c6b62ff0a1165c1b2a0829feccb49 -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.1/equalsverifier-signedjar-test-0.1.jar.sha1: -------------------------------------------------------------------------------- 1 | f6548c4a55d00129dd6a21dabab38327c506ba16 -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.1/equalsverifier-signedjar-test-0.1.pom: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | nl.jqno.equalsverifier 6 | equalsverifier-signedjar-test 7 | 0.1 8 | POM was created from install:install-file 9 | 10 | -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.1/equalsverifier-signedjar-test-0.1.pom.md5: -------------------------------------------------------------------------------- 1 | 263b2935da4a42513d21c0c5f9e12c9b -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.1/equalsverifier-signedjar-test-0.1.pom.sha1: -------------------------------------------------------------------------------- 1 | 49bdc90a2fd07095cb34c68099edc9f589e02641 -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.2/equalsverifier-signedjar-test-0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.2/equalsverifier-signedjar-test-0.2.jar -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.2/equalsverifier-signedjar-test-0.2.jar.md5: -------------------------------------------------------------------------------- 1 | 02abdd10d35f0f36708a1fc97e85487a -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.2/equalsverifier-signedjar-test-0.2.jar.sha1: -------------------------------------------------------------------------------- 1 | 16a21459d357a6f2ad535d4f83a0278275f8c1a6 -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.2/equalsverifier-signedjar-test-0.2.pom: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | nl.jqno.equalsverifier 6 | equalsverifier-signedjar-test 7 | 0.2 8 | POM was created from install:install-file 9 | 10 | -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.2/equalsverifier-signedjar-test-0.2.pom.md5: -------------------------------------------------------------------------------- 1 | e425efcd17ca722c39955c33cf4a1b92 -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/0.2/equalsverifier-signedjar-test-0.2.pom.sha1: -------------------------------------------------------------------------------- 1 | b0d1d2e9790812fdf055ed6ee04e94a603e0c381 -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/maven-metadata-local.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | nl.jqno.equalsverifier 4 | equalsverifier-signedjar-test 5 | 6 | 0.2 7 | 8 | 0.1 9 | 0.2 10 | 11 | 20180201071543 12 | 13 | 14 | -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/maven-metadata-local.xml.md5: -------------------------------------------------------------------------------- 1 | 72622fa2856fe9b6ed65f606bdedcba1 -------------------------------------------------------------------------------- /equalsverifier-test/lib/nl/jqno/equalsverifier/equalsverifier-signedjar-test/maven-metadata-local.xml.sha1: -------------------------------------------------------------------------------- 1 | e98de6e2d3e6af928b5394dae0a3e2bfddeff9c0 -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/coverage/HandwrittenGetClassPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.coverage; 2 | 3 | import nl.jqno.equalsverifier_testhelpers.types.Color; 4 | 5 | public final class HandwrittenGetClassPoint { 6 | 7 | private final int x; 8 | private final int y; 9 | private final Color color; 10 | 11 | public HandwrittenGetClassPoint(int x, int y, Color color) { 12 | this.x = x; 13 | this.y = y; 14 | this.color = color; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (obj == null || getClass() != obj.getClass()) { 20 | return false; 21 | } 22 | HandwrittenGetClassPoint other = (HandwrittenGetClassPoint) obj; 23 | return x == other.x && y == other.y && (color == null ? other.color == null : color.equals(other.color)); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | int result = 17; 29 | result = 31 * result + x; 30 | result = 31 * result + y; 31 | result = 31 * result + (color == null ? 0 : color.hashCode()); 32 | return result; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/coverage/HandwrittenInstanceOfPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.coverage; 2 | 3 | import nl.jqno.equalsverifier_testhelpers.types.Color; 4 | 5 | public final class HandwrittenInstanceOfPoint { 6 | 7 | private final int x; 8 | private final int y; 9 | private final Color color; 10 | 11 | public HandwrittenInstanceOfPoint(int x, int y, Color color) { 12 | this.x = x; 13 | this.y = y; 14 | this.color = color; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof HandwrittenInstanceOfPoint)) { 20 | return false; 21 | } 22 | HandwrittenInstanceOfPoint other = (HandwrittenInstanceOfPoint) obj; 23 | return x == other.x && y == other.y && (color == null ? other.color == null : color.equals(other.color)); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | int result = 17; 29 | result = 31 * result + x; 30 | result = 31 * result + y; 31 | result = 31 * result + (color == null ? 0 : color.hashCode()); 32 | return result; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/coverage/PatternMatchInstanceofPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.coverage; 2 | 3 | import nl.jqno.equalsverifier_testhelpers.types.Color; 4 | 5 | public final class PatternMatchInstanceofPoint { 6 | 7 | private final int x; 8 | private final int y; 9 | private final Color color; 10 | 11 | public PatternMatchInstanceofPoint(int x, int y, Color color) { 12 | this.x = x; 13 | this.y = y; 14 | this.color = color; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | return obj instanceof PatternMatchInstanceofPoint other 20 | && x == other.x 21 | && y == other.y 22 | && (color == null ? other.color == null : color.equals(other.color)); 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | int result = 17; 28 | result = 31 * result + x; 29 | result = 31 * result + y; 30 | result = 31 * result + (color == null ? 0 : color.hashCode()); 31 | return result; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/InstanceofPatternMatchTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extended_contract; 2 | 3 | import java.util.Objects; 4 | 5 | import nl.jqno.equalsverifier.EqualsVerifier; 6 | import org.junit.jupiter.api.Test; 7 | 8 | class InstanceofPatternMatchTest { 9 | 10 | @Test 11 | void succeed_whenEqualsUsesInstanceofPatternMatch() { 12 | EqualsVerifier.forClass(Point.class).verify(); 13 | } 14 | 15 | static final class Point { 16 | 17 | private final int x; 18 | private final int y; 19 | 20 | public Point(int x, int y) { 21 | this.x = x; 22 | this.y = y; 23 | } 24 | 25 | @Override 26 | public boolean equals(Object obj) { 27 | return this == obj || (obj instanceof Point p && p.x == x && p.y == y); 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return Objects.hash(x, y); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/InterfaceTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extended_contract; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import org.junit.jupiter.api.Test; 5 | 6 | class InterfaceTest { 7 | 8 | @Test 9 | void succeed_whenClassIsAnInterface() { 10 | EqualsVerifier.forClass(CharSequence.class).verify(); 11 | } 12 | 13 | @Test 14 | void succeed_whenClassIsAnEmptyInterface() { 15 | EqualsVerifier.forClass(Interface.class).verify(); 16 | } 17 | 18 | interface Interface {} 19 | } 20 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/JavaCollectionSubclassTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extended_contract; 2 | 3 | import java.util.ArrayList; 4 | 5 | import nl.jqno.equalsverifier.EqualsVerifier; 6 | import nl.jqno.equalsverifier_testhelpers.ExpectedException; 7 | import org.junit.jupiter.api.Test; 8 | 9 | class JavaCollectionSubclassTest { 10 | 11 | private static final String MESSAGE_FRAGMENT = "cannot verify subclasses of"; 12 | 13 | @Test 14 | void failWithHelpfulMessage_whenVerifyingArrayListSubclass() { 15 | ExpectedException 16 | .when(() -> EqualsVerifier.forClass(CustomArrayList.class).verify()) 17 | .assertFailure() 18 | .assertMessageContains(MESSAGE_FRAGMENT, ArrayList.class.getCanonicalName()); 19 | } 20 | 21 | private static final class CustomArrayList extends ArrayList { 22 | 23 | private static final long serialVersionUID = 1L; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extended_contract/JavaxClassesTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extended_contract; 2 | 3 | import java.util.Objects; 4 | import javax.naming.Reference; 5 | import javax.swing.tree.DefaultMutableTreeNode; 6 | 7 | import nl.jqno.equalsverifier.EqualsVerifier; 8 | import org.junit.jupiter.api.Test; 9 | 10 | // CHECKSTYLE OFF: ParameterNumber 11 | 12 | class JavaxClassesTest { 13 | 14 | @Test 15 | void succeed_whenClassUsesJavaxClasses() { 16 | EqualsVerifier.forClass(JavaxContainer.class).verify(); 17 | } 18 | 19 | static final class JavaxContainer { 20 | 21 | private final Reference ref; 22 | private final DefaultMutableTreeNode node; 23 | 24 | public JavaxContainer(Reference ref, DefaultMutableTreeNode node) { 25 | this.ref = ref; 26 | this.node = node; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object obj) { 31 | return obj instanceof JavaxContainer other 32 | && Objects.equals(ref, other.ref) 33 | && Objects.equals(node, other.node); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | return Objects.hash(ref, node); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/AnnotationNonNullFieldsTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import nl.jqno.equalsverifier.integration.extra_features.nonnull.springframework.NonNullFieldsOnPackage; 5 | import org.junit.jupiter.api.Test; 6 | 7 | class AnnotationNonNullFieldsTest { 8 | 9 | @Test 10 | void succeed_whenEqualsDoesntCheckForNull_givenNonNullFieldsAnnotationOnPackage() { 11 | EqualsVerifier.forClass(NonNullFieldsOnPackage.class).verify(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/OptionalDependencySanityTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import nl.jqno.equalsverifier.EqualsVerifier; 6 | import nl.jqno.equalsverifier.internal.reflection.Util; 7 | import nl.jqno.equalsverifier_testhelpers.ExpectedException; 8 | import nl.jqno.equalsverifier_testhelpers.types.GetClassPoint; 9 | import org.junit.jupiter.api.Test; 10 | 11 | public class OptionalDependencySanityTest { 12 | @Test 13 | void mockitoIsUnavailable() { 14 | var mockito = Util.classForName("org.mockito.Mockito"); 15 | assertThat(mockito).isNull(); 16 | } 17 | 18 | @Test 19 | void mockitoIsCorrectlyReported() { 20 | ExpectedException 21 | .when(() -> EqualsVerifier.forClass(GetClassPoint.class).verify()) 22 | .assertFailure() 23 | .assertMessageContains("Mockito: not available"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/eclipse/NonnullEclipseOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.eclipse; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullEclipseOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NonnullEclipseOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NonnullEclipseOnPackage)) { 16 | return false; 17 | } 18 | NonnullEclipseOnPackage other = (NonnullEclipseOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/eclipse/package-info.java: -------------------------------------------------------------------------------- 1 | /** Applies Eclipse's NonNullByDefault annotation to the package. */ 2 | @NonNullByDefault 3 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.eclipse; 4 | 5 | import nl.jqno.equalsverifier_testhelpers.annotations.org.eclipse.jdt.annotation.NonNullByDefault; 6 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/findbugs1x/custom/NonnullFindbugs1xCustomOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.findbugs1x.custom; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullFindbugs1xCustomOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NonnullFindbugs1xCustomOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NonnullFindbugs1xCustomOnPackage)) { 16 | return false; 17 | } 18 | NonnullFindbugs1xCustomOnPackage other = (NonnullFindbugs1xCustomOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/findbugs1x/custom/NonnullFindbugs1xWithCheckForNullOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.findbugs1x.custom; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullFindbugs1xWithCheckForNullOnPackage { 6 | 7 | private final Object o; 8 | 9 | @edu.umd.cs.findbugs.annotations.CheckForNull 10 | private final Object p; 11 | 12 | public NonnullFindbugs1xWithCheckForNullOnPackage(Object o, Object p) { 13 | this.o = o; 14 | this.p = p; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof NonnullFindbugs1xWithCheckForNullOnPackage)) { 20 | return false; 21 | } 22 | NonnullFindbugs1xWithCheckForNullOnPackage other = (NonnullFindbugs1xWithCheckForNullOnPackage) obj; 23 | return o.equals(other.o) && p.equals(other.p); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(o, p); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/findbugs1x/custom/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Applies a custom NonNull annotation to the whole package using Findbugs 1.x's DefaultAnnotation. 3 | */ 4 | @DefaultAnnotation(NonNull.class) 5 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.findbugs1x.custom; 6 | 7 | import nl.jqno.equalsverifier_testhelpers.annotations.NonNull; 8 | import nl.jqno.equalsverifier_testhelpers.annotations.edu.umd.cs.findbugs.annotations.DefaultAnnotation; 9 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/findbugs1x/javax/NonnullFindbugs1xJavaxOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.findbugs1x.javax; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullFindbugs1xJavaxOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NonnullFindbugs1xJavaxOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NonnullFindbugs1xJavaxOnPackage)) { 16 | return false; 17 | } 18 | NonnullFindbugs1xJavaxOnPackage other = (NonnullFindbugs1xJavaxOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/findbugs1x/javax/NonnullFindbugs1xWithNullableOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.findbugs1x.javax; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullFindbugs1xWithNullableOnPackage { 6 | 7 | private final Object o; 8 | 9 | @edu.umd.cs.findbugs.annotations.Nullable 10 | private final Object p; 11 | 12 | public NonnullFindbugs1xWithNullableOnPackage(Object o, Object p) { 13 | this.o = o; 14 | this.p = p; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof NonnullFindbugs1xWithNullableOnPackage)) { 20 | return false; 21 | } 22 | NonnullFindbugs1xWithNullableOnPackage other = (NonnullFindbugs1xWithNullableOnPackage) obj; 23 | return o.equals(other.o) && p.equals(other.p); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(o, p); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/findbugs1x/javax/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Applies Javax's Nonnull annotation to the whole package using Findbugs 1.x's DefaultAnnotation. 3 | */ 4 | @DefaultAnnotation(Nonnull.class) 5 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.findbugs1x.javax; 6 | 7 | import javax.annotation.Nonnull; 8 | 9 | import nl.jqno.equalsverifier_testhelpers.annotations.edu.umd.cs.findbugs.annotations.DefaultAnnotation; 10 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jspecify/NullMarkedOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jspecify; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NullMarkedOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NullMarkedOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NullMarkedOnPackage)) { 16 | return false; 17 | } 18 | NullMarkedOnPackage other = (NullMarkedOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jspecify/package-info.java: -------------------------------------------------------------------------------- 1 | /** Applies JSpecify's NullMarked annotation to the package. */ 2 | @NullMarked 3 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jspecify; 4 | 5 | import nl.jqno.equalsverifier_testhelpers.annotations.org.jspecify.annotations.NullMarked; 6 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/custom/NonnullJsr305CustomOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.custom; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullJsr305CustomOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NonnullJsr305CustomOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NonnullJsr305CustomOnPackage)) { 16 | return false; 17 | } 18 | NonnullJsr305CustomOnPackage other = (NonnullJsr305CustomOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/custom/NonnullJsr305WithNullableOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.custom; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullJsr305WithNullableOnPackage { 6 | 7 | private final Object o; 8 | 9 | @edu.umd.cs.findbugs.annotations.Nullable 10 | private final Object p; 11 | 12 | public NonnullJsr305WithNullableOnPackage(Object o, Object p) { 13 | this.o = o; 14 | this.p = p; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof NonnullJsr305WithNullableOnPackage)) { 20 | return false; 21 | } 22 | NonnullJsr305WithNullableOnPackage other = (NonnullJsr305WithNullableOnPackage) obj; 23 | return o.equals(other.o) && p.equals(other.p); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(o, p); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/custom/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Applies a custom Nonnull annotation to the whole package using JSR305's default annotation system. 3 | */ 4 | @DefaultNonnullCustom 5 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.custom; 6 | 7 | import nl.jqno.equalsverifier_testhelpers.annotations.DefaultNonnullCustom; 8 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/inapplicable/NonnullJsr305InapplicableOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.inapplicable; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullJsr305InapplicableOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NonnullJsr305InapplicableOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NonnullJsr305InapplicableOnPackage)) { 16 | return false; 17 | } 18 | NonnullJsr305InapplicableOnPackage other = (NonnullJsr305InapplicableOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/inapplicable/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Applies a Nonnull annotation to the whole package using JSR305's default annotation system, but in a way that makes 3 | * Nonnull inapplicable. 4 | */ 5 | @DefaultNonnullInapplicable 6 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.inapplicable; 7 | 8 | import nl.jqno.equalsverifier_testhelpers.annotations.DefaultNonnullInapplicable; 9 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/javax/NonnullJsr305JavaxOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.javax; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullJsr305JavaxOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NonnullJsr305JavaxOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NonnullJsr305JavaxOnPackage)) { 16 | return false; 17 | } 18 | NonnullJsr305JavaxOnPackage other = (NonnullJsr305JavaxOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/javax/NonnullJsr305WithCheckForNullOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.javax; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonnullJsr305WithCheckForNullOnPackage { 6 | 7 | private final Object o; 8 | 9 | @edu.umd.cs.findbugs.annotations.CheckForNull 10 | private final Object p; 11 | 12 | public NonnullJsr305WithCheckForNullOnPackage(Object o, Object p) { 13 | this.o = o; 14 | this.p = p; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof NonnullJsr305WithCheckForNullOnPackage)) { 20 | return false; 21 | } 22 | NonnullJsr305WithCheckForNullOnPackage other = (NonnullJsr305WithCheckForNullOnPackage) obj; 23 | return o.equals(other.o) && p.equals(other.p); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hash(o, p); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/javax/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Applies Javax's Nonnull annotation to the whole package using JSR305's default annotation system. 3 | */ 4 | @DefaultNonnullJavax 5 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.javax; 6 | 7 | import nl.jqno.equalsverifier_testhelpers.annotations.DefaultNonnullJavax; 8 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/parametersarenonnullbydefault/ParametersAreNonnullByDefaultOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.parametersarenonnullbydefault; 2 | 3 | import java.util.Objects; 4 | 5 | public final class ParametersAreNonnullByDefaultOnPackage { 6 | 7 | private final Object o; 8 | 9 | public ParametersAreNonnullByDefaultOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof ParametersAreNonnullByDefaultOnPackage)) { 16 | return false; 17 | } 18 | ParametersAreNonnullByDefaultOnPackage other = (ParametersAreNonnullByDefaultOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/jsr305/parametersarenonnullbydefault/package-info.java: -------------------------------------------------------------------------------- 1 | /** Applies JSR305's ParametersAreNonnullByDefault annotation to the whole package. */ 2 | @ParametersAreNonnullByDefault 3 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.jsr305.parametersarenonnullbydefault; 4 | 5 | import javax.annotation.ParametersAreNonnullByDefault; 6 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/springframework/NonNullFieldsOnPackage.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.springframework; 2 | 3 | import java.util.Objects; 4 | 5 | public final class NonNullFieldsOnPackage { 6 | 7 | private final Object o; 8 | 9 | public NonNullFieldsOnPackage(Object o) { 10 | this.o = o; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof NonNullFieldsOnPackage)) { 16 | return false; 17 | } 18 | NonNullFieldsOnPackage other = (NonNullFieldsOnPackage) obj; 19 | return o.equals(other.o); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(o); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/nonnull/springframework/package-info.java: -------------------------------------------------------------------------------- 1 | /** Applies Spring's NonNullFields annotation to the package. */ 2 | @NonNullFields 3 | package nl.jqno.equalsverifier.integration.extra_features.nonnull.springframework; 4 | 5 | import nl.jqno.equalsverifier_testhelpers.annotations.org.springframework.lang.NonNullFields; 6 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/simple_package/SimplePoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.simple_package; 2 | 3 | import java.util.Objects; 4 | 5 | import nl.jqno.equalsverifier_testhelpers.types.Color; 6 | 7 | public class SimplePoint { 8 | 9 | private int x; 10 | private int y; 11 | private Color color; 12 | 13 | public SimplePoint(int x) { 14 | this.x = x; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object o) { 19 | if (this == o) { 20 | return true; 21 | } 22 | if (o == null || getClass() != o.getClass()) { 23 | return false; 24 | } 25 | SimplePoint that = (SimplePoint) o; 26 | return x == that.x && y == that.y && color == that.color; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return Objects.hash(x, y, color); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/extra_features/simple_package/subpackage/SimplePoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.extra_features.simple_package.subpackage; 2 | 3 | import java.util.Objects; 4 | 5 | import nl.jqno.equalsverifier_testhelpers.types.Color; 6 | 7 | public class SimplePoint { 8 | 9 | private int x; 10 | private int y; 11 | private Color color; 12 | 13 | public SimplePoint(int x) { 14 | this.x = x; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object o) { 19 | if (this == o) { 20 | return true; 21 | } 22 | if (o == null || getClass() != o.getClass()) { 23 | return false; 24 | } 25 | SimplePoint that = (SimplePoint) o; 26 | return x == that.x && y == that.y && color == that.color; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return Objects.hash(x, y, color); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/operational/ModuleTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.operational; 2 | 3 | import static org.assertj.core.api.Assertions.assertThat; 4 | 5 | import org.junit.jupiter.api.Test; 6 | 7 | public class ModuleTest { 8 | @Test 9 | void sanity() { 10 | // We want the tests in this module to be run on the class path, not the module path. 11 | assertThat(getClass().getModule().isNamed()).isFalse(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/integration/operational/SignedJarTest.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.integration.operational; 2 | 3 | import nl.jqno.equalsverifier.EqualsVerifier; 4 | import nl.jqno.equalsverifier.signedjar.SignedJarPoint; 5 | import org.junit.jupiter.api.Test; 6 | 7 | class SignedJarTest { 8 | 9 | @Test 10 | void succeed_whenTestingAClassFromASignedJar() { 11 | EqualsVerifier.forClass(SignedJarPoint.class).verify(); 12 | } 13 | 14 | @Test 15 | void succeed_whenTestingAClassThatExtendsFromAClassFromASignedJar() { 16 | EqualsVerifier.forClass(SubclassOfSignedJarPoint.class).verify(); 17 | } 18 | 19 | static final class SubclassOfSignedJarPoint extends SignedJarPoint { 20 | 21 | public SubclassOfSignedJarPoint(int x, int y) { 22 | super(x, y); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/A.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct; 2 | 3 | public final class A { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public A(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof A)) { 16 | return false; 17 | } 18 | A p = (A) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/B.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct; 2 | 3 | public final class B { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public B(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof B)) { 16 | return false; 17 | } 18 | B p = (B) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/C.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct; 2 | 3 | public final class C { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public C(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof C)) { 16 | return false; 17 | } 18 | C p = (C) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/A.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage; 2 | 3 | public final class A { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public A(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof A)) { 16 | return false; 17 | } 18 | A p = (A) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/B.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage; 2 | 3 | public final class B { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public B(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof B)) { 16 | return false; 17 | } 18 | B p = (B) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/subpackage/A.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage; 2 | 3 | public final class A { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public A(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof A)) { 16 | return false; 17 | } 18 | A p = (A) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/subpackage/B.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage; 2 | 3 | public final class B { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public B(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof B)) { 16 | return false; 17 | } 18 | B p = (B) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/correct/subpackage/subpackage/D.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.correct.subpackage.subpackage; 2 | 3 | public final class D { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public D(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof D)) { 16 | return false; 17 | } 18 | D p = (D) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/somerecursive/Nonrecursive.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.somerecursive; 2 | 3 | public final class Nonrecursive { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public Nonrecursive(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof Nonrecursive)) { 16 | return false; 17 | } 18 | Nonrecursive p = (Nonrecursive) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/somerecursive/RecursiveA.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.somerecursive; 2 | 3 | import java.util.Objects; 4 | 5 | public final class RecursiveA { 6 | 7 | private final RecursiveB b; 8 | 9 | public RecursiveA(RecursiveB b) { 10 | this.b = b; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof RecursiveA)) { 16 | return false; 17 | } 18 | RecursiveA p = (RecursiveA) obj; 19 | return Objects.equals(b, p.b); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(b); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + b; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/somerecursive/RecursiveB.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.somerecursive; 2 | 3 | import java.util.Objects; 4 | 5 | public final class RecursiveB { 6 | 7 | private final RecursiveA a; 8 | 9 | public RecursiveB(RecursiveA a) { 10 | this.a = a; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof RecursiveB)) { 16 | return false; 17 | } 18 | RecursiveB p = (RecursiveB) obj; 19 | return Objects.equals(a, p.a); 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return Objects.hash(a); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + a; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubA.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public final class SubA extends SuperA { 4 | 5 | private final int i; 6 | 7 | public SubA(int i) { 8 | this.i = i; 9 | } 10 | 11 | @Override 12 | public boolean equals(Object obj) { 13 | if (!(obj instanceof SubA)) { 14 | return false; 15 | } 16 | SubA other = (SubA) obj; 17 | return i == other.i; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return 31 * i; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return getClass().getSimpleName() + ":" + i; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SubI.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public interface SubI extends SuperI {} 4 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SuperA.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public class SuperA {} 4 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/subclasses/SuperI.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.subclasses; 2 | 3 | public interface SuperI {} 4 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/twoincorrect/IncorrectM.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.twoincorrect; 2 | 3 | public class IncorrectM { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public IncorrectM(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof IncorrectM)) { 16 | return false; 17 | } 18 | IncorrectM p = (IncorrectM) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/twoincorrect/IncorrectN.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.twoincorrect; 2 | 3 | public final class IncorrectN { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public IncorrectN(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof IncorrectN)) { 16 | return false; 17 | } 18 | IncorrectN p = (IncorrectN) obj; 19 | return p.x == x && p.y != y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/twoincorrect/X.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.twoincorrect; 2 | 3 | public final class X { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public X(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof X)) { 16 | return false; 17 | } 18 | X p = (X) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/twoincorrect/Y.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.twoincorrect; 2 | 3 | public final class Y { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public Y(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof Y)) { 16 | return false; 17 | } 18 | Y p = (Y) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/twoincorrect/Z.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.twoincorrect; 2 | 3 | public final class Z { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public Z(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof Z)) { 16 | return false; 17 | } 18 | Z p = (Z) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/twoincorrect/subpackage/IncorrectO.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.twoincorrect.subpackage; 2 | 3 | public class IncorrectO { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public IncorrectO(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof IncorrectO)) { 16 | return false; 17 | } 18 | IncorrectO p = (IncorrectO) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-test/src/test/java/nl/jqno/equalsverifier/testhelpers/packages/twoincorrect/subpackage/IncorrectP.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier.testhelpers.packages.twoincorrect.subpackage; 2 | 3 | public final class IncorrectP { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public IncorrectP(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof IncorrectP)) { 16 | return false; 17 | } 18 | IncorrectP p = (IncorrectP) obj; 19 | return p.x == x && p.y != y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | nl.jqno.equalsverifier 7 | equalsverifier-parent 8 | 4.0.1-SNAPSHOT 9 | 10 | jar 11 | 12 | equalsverifier-testhelpers 13 | EqualsVerifier | testhelpers 14 | 15 | 16 | 17 | com.google.code.findbugs 18 | jsr305 19 | ${version.jsr305} 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/Util.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers; 2 | 3 | import java.lang.reflect.Constructor; 4 | 5 | public final class Util { 6 | 7 | private Util() {} 8 | 9 | public static void coverThePrivateConstructor(Class type) { 10 | try { 11 | Constructor constructor = type.getDeclaredConstructor(); 12 | constructor.setAccessible(true); 13 | constructor.newInstance(); 14 | } 15 | catch (Exception e) { 16 | throw new AssertionError("Could not call constructor of " + type.getName(), e); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/AnnotationWithAnnotation.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target(ElementType.TYPE) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | @TypeAnnotationClassRetention 8 | public @interface AnnotationWithAnnotation {} 9 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/AnnotationWithValues.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Target({ ElementType.TYPE, ElementType.FIELD }) 6 | @Retention(RetentionPolicy.RUNTIME) 7 | public @interface AnnotationWithValues { 8 | Class[] annotations(); 9 | 10 | ElementType elementType(); 11 | } 12 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/DefaultNonnullCustom.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import javax.annotation.meta.TypeQualifierDefault; 8 | 9 | @Documented 10 | @NotNull 11 | @TypeQualifierDefault(ElementType.FIELD) 12 | @Retention(RetentionPolicy.CLASS) 13 | public @interface DefaultNonnullCustom {} 14 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/DefaultNonnullInapplicable.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import javax.annotation.Nonnull; 8 | import javax.annotation.meta.TypeQualifierDefault; 9 | 10 | @Documented 11 | @Nonnull 12 | @TypeQualifierDefault(ElementType.TYPE) 13 | @Retention(RetentionPolicy.CLASS) 14 | public @interface DefaultNonnullInapplicable {} 15 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/DefaultNonnullJavax.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.Documented; 4 | import java.lang.annotation.ElementType; 5 | import java.lang.annotation.Retention; 6 | import java.lang.annotation.RetentionPolicy; 7 | import javax.annotation.meta.TypeQualifierDefault; 8 | 9 | import nl.jqno.equalsverifier_testhelpers.annotations.javax.annotation.Nonnull; 10 | 11 | @Documented 12 | @Nonnull 13 | @TypeQualifierDefault({ ElementType.FIELD, ElementType.TYPE }) 14 | @Retention(RetentionPolicy.CLASS) 15 | public @interface DefaultNonnullJavax {} 16 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/DifficultAnnotation.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.TYPE_USE }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface DifficultAnnotation { 11 | String[] strings() default { "a", "b", "c" }; 12 | 13 | int[] ints() default { 1, 2, 3 }; 14 | } 15 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/Embeddable.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Embeddable {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/Entity.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Entity {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/FieldAnnotationClassRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface FieldAnnotationClassRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/FieldAnnotationDoesntInherit.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface FieldAnnotationDoesntInherit {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/FieldAnnotationInherits.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface FieldAnnotationInherits {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/FieldAnnotationRuntimeRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface FieldAnnotationRuntimeRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/Id.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.METHOD, ElementType.FIELD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Id {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/Immutable.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Because there's no standard Immutable annotation, we define our own so that EqualsVerifier can work with any 10 | * annotation called Immutable. 11 | */ 12 | @Target(ElementType.TYPE) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface Immutable {} 15 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/Inapplicable.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.TYPE }) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface Inapplicable {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/MappedSuperclass.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface MappedSuperclass {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/MethodAnnotationClassRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface MethodAnnotationClassRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/MethodAnnotationRuntimeRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface MethodAnnotationRuntimeRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/NaturalId.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.METHOD, ElementType.FIELD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface NaturalId {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/NonNull.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Because there's no standard Nonnull/NonNull/NotNull annotation, we define our own so that EqualsVerifier can work 10 | * with any non-null annotation. 11 | */ 12 | @Target(ElementType.FIELD) 13 | @Retention(RetentionPolicy.CLASS) 14 | public @interface NonNull {} 15 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/NotNull.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Because there's no standard Nonnull/NonNull/NotNull annotation, we define our own so that EqualsVerifier can work 10 | * with any non-null annotation. 11 | */ 12 | @Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE }) 13 | @Retention(RetentionPolicy.CLASS) 14 | public @interface NotNull {} 15 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/PackageAnnotation.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.PACKAGE) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface PackageAnnotation {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/PostProcess.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface PostProcess {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/Transient.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Transient {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeAnnotationClassRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface TypeAnnotationClassRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeAnnotationDoesntInherit.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface TypeAnnotationDoesntInherit {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeAnnotationInherits.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface TypeAnnotationInherits {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeAnnotationRuntimeRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface TypeAnnotationRuntimeRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeUseAnnotationClassRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE_USE) 9 | @Retention(RetentionPolicy.CLASS) 10 | public @interface TypeUseAnnotationClassRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeUseAnnotationDoesntInherit.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE_USE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface TypeUseAnnotationDoesntInherit {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeUseAnnotationInherits.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE_USE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface TypeUseAnnotationInherits {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/TypeUseAnnotationRuntimeRetention.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE_USE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface TypeUseAnnotationRuntimeRetention {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/edu/umd/cs/findbugs/annotations/DefaultAnnotation.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.edu.umd.cs.findbugs.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * This annotation serves as a paceholder for the real {@link edu.umd.cs.findbugs.annotations.DefaultAnnotation}, which 7 | * is deprecated. We use this annotation to avoid warnings in places where we can't suppress the warning. 8 | */ 9 | @Target(ElementType.PACKAGE) 10 | @Retention(RetentionPolicy.CLASS) 11 | public @interface DefaultAnnotation { 12 | Class[] value(); 13 | } 14 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/annotation/Nonnull.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.RetentionPolicy; 5 | import javax.annotation.meta.TypeQualifier; 6 | 7 | /** 8 | * The Java Platform Module System in Java 9 makes it hard access the javax.annotation.* annotations, because they live 9 | * in a dependency but end up inside a split package through the java.xml.ws.annotation module. The latter is slated to 10 | * be removed, but it hasn't happened yet in Java 9. 11 | * 12 | *

13 | * Adding javax.annotation.Nonnull to a class works fine, but accessing it with reflection causes NoClassDefFoundErrors. 14 | * 15 | *

16 | * This annotation can be used in tests to replace the regular javax.annotation.Nonnull. 17 | * 18 | *

19 | * For more info, see https://blog.codefx.org/java/jsr-305-java-9/ 20 | */ 21 | @TypeQualifier 22 | @Retention(RetentionPolicy.RUNTIME) 23 | public @interface Nonnull {} 24 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/Basic.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.METHOD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Basic { 11 | FetchType fetch() default FetchType.EAGER; 12 | } 13 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/ElementCollection.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.METHOD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ElementCollection { 11 | FetchType fetch() default FetchType.EAGER; 12 | } 13 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/Embeddable.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Embeddable {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/EmbeddedId.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.METHOD, ElementType.FIELD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface EmbeddedId {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/Entity.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Entity {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/FetchType.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | public enum FetchType { 4 | LAZY, EAGER 5 | } 6 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/GeneratedValue.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.METHOD, ElementType.FIELD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface GeneratedValue {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/Id.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.METHOD, ElementType.FIELD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Id {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/ManyToMany.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.METHOD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ManyToMany { 11 | FetchType fetch() default FetchType.EAGER; 12 | } 13 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/ManyToOne.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.METHOD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface ManyToOne { 11 | FetchType fetch() default FetchType.EAGER; 12 | } 13 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/MappedSuperclass.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.TYPE) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface MappedSuperclass {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/OneToMany.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.METHOD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface OneToMany { 11 | FetchType fetch() default FetchType.EAGER; 12 | } 13 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/OneToOne.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.FIELD, ElementType.METHOD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface OneToOne { 11 | FetchType fetch() default FetchType.EAGER; 12 | } 13 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/javax/persistence/Transient.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.javax.persistence; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.FIELD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface Transient {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/org/eclipse/jdt/annotation/NonNullByDefault.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.org.eclipse.jdt.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * This annotation serves as a placeholder for the real {@link org.eclipse.jdt.annotation.NonNullByDefault} annotation. 7 | * However, since that annotation is compiled for Java 8, and this code base must support Java 6, we use this copy 8 | * instead. 9 | */ 10 | @Documented 11 | @Retention(RetentionPolicy.CLASS) 12 | @Target({ ElementType.PACKAGE, ElementType.TYPE }) 13 | public @interface NonNullByDefault {} 14 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/org/hibernate/annotations/NaturalId.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.org.hibernate.annotations; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target({ ElementType.METHOD, ElementType.FIELD }) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface NaturalId {} 11 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/org/jspecify/annotations/NullMarked.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.org.jspecify.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * This annotation serves as a placeholder for the real {@link org.jspecify.annotations.NullMarked} annotation. However, 7 | * since that annotation is compiled for Java 9, and this code base must support Java 8, we use this copy instead. 8 | */ 9 | @Retention(RetentionPolicy.RUNTIME) 10 | @Target({ ElementType.PACKAGE, ElementType.TYPE }) 11 | public @interface NullMarked {} 12 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/org/jspecify/annotations/Nullable.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.org.jspecify.annotations; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Retention(RetentionPolicy.RUNTIME) 6 | @Target(ElementType.TYPE_USE) 7 | public @interface Nullable {} 8 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/annotations/org/springframework/lang/NonNullFields.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.annotations.org.springframework.lang; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Retention(RetentionPolicy.RUNTIME) 6 | @Target(ElementType.PACKAGE) 7 | public @interface NonNullFields {} 8 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/BlindlyEqualsColorPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public final class BlindlyEqualsColorPoint extends BlindlyEqualsPoint { 6 | 7 | private final Color color; 8 | 9 | public BlindlyEqualsColorPoint(int x, int y, Color color) { 10 | super(x, y); 11 | this.color = color; 12 | } 13 | 14 | @Override 15 | protected boolean blindlyEquals(Object o) { 16 | if (!(o instanceof BlindlyEqualsColorPoint)) { 17 | return false; 18 | } 19 | BlindlyEqualsColorPoint cp = (BlindlyEqualsColorPoint) o; 20 | return super.blindlyEquals(cp) && cp.color == this.color; 21 | } 22 | 23 | @Override 24 | public int hashCode() { 25 | return Objects.hashCode(color) + (31 * super.hashCode()); 26 | } 27 | 28 | @Override 29 | public String toString() { 30 | return super.toString() + "," + color; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/BlindlyEqualsPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class BlindlyEqualsPoint { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public BlindlyEqualsPoint(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | protected boolean blindlyEquals(Object o) { 14 | if (!(o instanceof BlindlyEqualsPoint)) { 15 | return false; 16 | } 17 | BlindlyEqualsPoint p = (BlindlyEqualsPoint) o; 18 | return p.x == this.x && p.y == this.y; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object o) { 23 | return this.blindlyEquals(o) && ((BlindlyEqualsPoint) o).blindlyEquals(this); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return x + (31 * y); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return getClass().getSimpleName() + ":" + x + "," + y; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/CanEqualColorPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public final class CanEqualColorPoint extends CanEqualPoint { 6 | 7 | private final Color color; 8 | 9 | public CanEqualColorPoint(int x, int y, Color color) { 10 | super(x, y); 11 | this.color = color; 12 | } 13 | 14 | @Override 15 | public boolean canEqual(Object obj) { 16 | return obj instanceof CanEqualColorPoint; 17 | } 18 | 19 | @Override 20 | public boolean equals(Object obj) { 21 | if (!(obj instanceof CanEqualColorPoint)) { 22 | return false; 23 | } 24 | CanEqualColorPoint p = (CanEqualColorPoint) obj; 25 | return p.canEqual(this) && super.equals(p) && color == p.color; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | return Objects.hashCode(color) + (31 * super.hashCode()); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return super.toString() + "," + color; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/CanEqualPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class CanEqualPoint { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public CanEqualPoint(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | public boolean canEqual(Object obj) { 14 | return obj instanceof CanEqualPoint; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof CanEqualPoint)) { 20 | return false; 21 | } 22 | CanEqualPoint p = (CanEqualPoint) obj; 23 | return p.canEqual(this) && p.x == x && p.y == y; 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return x + (31 * y); 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return getClass().getSimpleName() + ":" + x + "," + y; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/Color.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public enum Color { 4 | YELLOW, BLUE, INDIGO 5 | } 6 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/ColorBlindColorPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public final class ColorBlindColorPoint extends Point { 4 | 5 | public final Color color; 6 | 7 | public ColorBlindColorPoint(int x, int y, Color color) { 8 | super(x, y); 9 | this.color = color; 10 | } 11 | 12 | @Override 13 | public final boolean equals(Object obj) { 14 | return super.equals(obj); 15 | } 16 | 17 | @Override 18 | public final int hashCode() { 19 | return super.hashCode(); 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return super.toString() + "," + color; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/ColorPoint3D.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public final class ColorPoint3D extends Point3D { 4 | 5 | final Color color; 6 | 7 | public ColorPoint3D(int x, int y, int z, Color color) { 8 | super(x, y, z); 9 | this.color = color; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/EqualSubclassForBlindlyEqualsPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class EqualSubclassForBlindlyEqualsPoint extends BlindlyEqualsPoint { 4 | 5 | public EqualSubclassForBlindlyEqualsPoint(int x, int y) { 6 | super(x, y); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/EqualSubclassForCanEqualPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class EqualSubclassForCanEqualPoint extends CanEqualPoint { 4 | 5 | public EqualSubclassForCanEqualPoint(int x, int y) { 6 | super(x, y); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/FinalMethodsPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class FinalMethodsPoint { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public FinalMethodsPoint(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public final boolean equals(Object obj) { 15 | if (!(obj instanceof FinalMethodsPoint)) { 16 | return false; 17 | } 18 | FinalMethodsPoint p = (FinalMethodsPoint) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public final int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/FinalPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public final class FinalPoint { 4 | 5 | private final int x; 6 | private final int y; 7 | 8 | public FinalPoint(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | public int getX() { 14 | return x; 15 | } 16 | 17 | public int getY() { 18 | return y; 19 | } 20 | 21 | @Override 22 | public boolean equals(Object obj) { 23 | if (!(obj instanceof FinalPoint)) { 24 | return false; 25 | } 26 | FinalPoint p = (FinalPoint) obj; 27 | return p.x == x && p.y == y; 28 | } 29 | 30 | @Override 31 | public int hashCode() { 32 | return x + (31 * y); 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return getClass().getSimpleName() + ":" + x + "," + y; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/FinalPointContainer.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public final class FinalPointContainer { 6 | 7 | private final FinalPoint point; 8 | 9 | public FinalPointContainer(FinalPoint point) { 10 | this.point = point; 11 | } 12 | 13 | public FinalPoint getPoint() { 14 | return point; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof FinalPointContainer)) { 20 | return false; 21 | } 22 | FinalPointContainer other = (FinalPointContainer) obj; 23 | return Objects.equals(point, other.point); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hashCode(point); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/GetClassPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public class GetClassPoint { 6 | 7 | private final int x; 8 | private final int y; 9 | 10 | public GetClassPoint(int x, int y) { 11 | this.x = x; 12 | this.y = y; 13 | } 14 | 15 | @Override 16 | public boolean equals(Object obj) { 17 | if (obj == null || obj.getClass() != getClass()) { 18 | return false; 19 | } 20 | GetClassPoint p = (GetClassPoint) obj; 21 | return p.x == x && p.y == y; 22 | } 23 | 24 | @Override 25 | public int hashCode() { 26 | return Objects.hash(x, y); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/ImmutableCanEqualPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import nl.jqno.equalsverifier_testhelpers.annotations.Immutable; 4 | 5 | @Immutable 6 | public class ImmutableCanEqualPoint { 7 | 8 | private int x; 9 | private int y; 10 | 11 | public ImmutableCanEqualPoint(int x, int y) { 12 | this.x = x; 13 | this.y = y; 14 | } 15 | 16 | public boolean canEqual(Object obj) { 17 | return obj instanceof ImmutableCanEqualPoint; 18 | } 19 | 20 | @Override 21 | public boolean equals(Object obj) { 22 | if (!(obj instanceof ImmutableCanEqualPoint)) { 23 | return false; 24 | } 25 | ImmutableCanEqualPoint p = (ImmutableCanEqualPoint) obj; 26 | return p.canEqual(this) && p.x == x && p.y == y; 27 | } 28 | 29 | @Override 30 | public int hashCode() { 31 | return x + (31 * y); 32 | } 33 | 34 | @Override 35 | public String toString() { 36 | return getClass().getSimpleName() + ":" + x + "," + y; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/Multiple.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class Multiple { 4 | 5 | private final int a; 6 | private final int b; 7 | 8 | public Multiple(int a, int b) { 9 | this.a = a; 10 | this.b = b; 11 | } 12 | 13 | @Override 14 | public final boolean equals(Object obj) { 15 | if (!(obj instanceof Multiple)) { 16 | return false; 17 | } 18 | Multiple other = (Multiple) obj; 19 | return a * b == other.a * other.b; 20 | } 21 | 22 | @Override 23 | public final int hashCode() { 24 | return a * b; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + a + "*" + b + "=" + (a * b); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/MutableCanEqualColorPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public final class MutableCanEqualColorPoint extends ImmutableCanEqualPoint { 6 | 7 | private Color color; 8 | 9 | public MutableCanEqualColorPoint(int x, int y, Color color) { 10 | super(x, y); 11 | this.color = color; 12 | } 13 | 14 | @Override 15 | public boolean canEqual(Object obj) { 16 | return obj instanceof MutableCanEqualColorPoint; 17 | } 18 | 19 | @Override 20 | public boolean equals(Object obj) { 21 | if (!(obj instanceof MutableCanEqualColorPoint)) { 22 | return false; 23 | } 24 | MutableCanEqualColorPoint p = (MutableCanEqualColorPoint) obj; 25 | return p.canEqual(this) && super.equals(p) && color == p.color; 26 | } 27 | 28 | @Override 29 | public int hashCode() { 30 | return Objects.hashCode(color) + (31 * super.hashCode()); 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return super.toString() + "," + color; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/MutablePoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class MutablePoint { 4 | 5 | private int x; 6 | private int y; 7 | 8 | public MutablePoint(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof MutablePoint)) { 16 | return false; 17 | } 18 | MutablePoint other = (MutablePoint) obj; 19 | return x == other.x && y == other.y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/Pair.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public class Pair { 6 | 7 | private final T left; 8 | private final U right; 9 | 10 | public Pair(T left, U right) { 11 | this.left = left; 12 | this.right = right; 13 | } 14 | 15 | @Override 16 | public boolean equals(Object obj) { 17 | if (!(obj instanceof Pair)) { 18 | return false; 19 | } 20 | @SuppressWarnings("unchecked") 21 | var other = (Pair) obj; 22 | return Objects.equals(left, other.left) && Objects.equals(right, other.right); 23 | } 24 | 25 | @Override 26 | public int hashCode() { 27 | return Objects.hash(left, right); 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return getClass().getSimpleName() + ": [" + left + ", " + right + "]"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/Point.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class Point { 4 | 5 | public final int x; 6 | public final int y; 7 | 8 | public Point(int x, int y) { 9 | this.x = x; 10 | this.y = y; 11 | } 12 | 13 | @Override 14 | public boolean equals(Object obj) { 15 | if (!(obj instanceof Point)) { 16 | return false; 17 | } 18 | Point p = (Point) obj; 19 | return p.x == x && p.y == y; 20 | } 21 | 22 | @Override 23 | public int hashCode() { 24 | return x + (31 * y); 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return getClass().getSimpleName() + ":" + x + "," + y; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/Point3D.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public class Point3D extends Point { 4 | 5 | public int z; 6 | 7 | public Point3D(int x, int y, int z) { 8 | super(x, y); 9 | this.z = z; 10 | } 11 | 12 | @Override 13 | public boolean equals(Object obj) { 14 | if (!(obj instanceof Point3D)) { 15 | return false; 16 | } 17 | return super.equals(obj) && ((Point3D) obj).z == z; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | return super.hashCode() + (31 * z); 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return super.toString() + "," + z; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/PointContainer.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public final class PointContainer { 6 | 7 | private final Point point; 8 | 9 | public PointContainer(Point point) { 10 | this.point = point; 11 | } 12 | 13 | public Point getPoint() { 14 | return point; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof PointContainer)) { 20 | return false; 21 | } 22 | PointContainer other = (PointContainer) obj; 23 | return Objects.equals(point, other.point); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hashCode(point); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/PointContainerOpenForSubclassAttack.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | import java.util.Objects; 4 | 5 | public final class PointContainerOpenForSubclassAttack { 6 | 7 | private final Point point; 8 | 9 | public PointContainerOpenForSubclassAttack(Point point) { 10 | this.point = point; 11 | } 12 | 13 | public Point getPoint() { 14 | return point; 15 | } 16 | 17 | @Override 18 | public boolean equals(Object obj) { 19 | if (!(obj instanceof PointContainerOpenForSubclassAttack)) { 20 | return false; 21 | } 22 | var other = (PointContainerOpenForSubclassAttack) obj; 23 | return Objects.equals(point, other.point); 24 | } 25 | 26 | @Override 27 | public int hashCode() { 28 | return Objects.hashCode(point); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/RecordPoint.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public record RecordPoint(int x, int y) {} 4 | -------------------------------------------------------------------------------- /equalsverifier-testhelpers/src/main/java/nl/jqno/equalsverifier_testhelpers/types/ThrowingInitializer.java: -------------------------------------------------------------------------------- 1 | package nl.jqno.equalsverifier_testhelpers.types; 2 | 3 | public final class ThrowingInitializer { 4 | { 5 | // Throwing something that will immediately be thrown when the class is constructed. 6 | if (true) { 7 | throw new IllegalStateException("initializing"); 8 | } 9 | } 10 | 11 | private ThrowingInitializer() {} 12 | 13 | public static final ThrowingInitializer X = new ThrowingInitializer(); 14 | public static final ThrowingInitializer Y = new ThrowingInitializer(); 15 | } 16 | -------------------------------------------------------------------------------- /jreleaser.yml: -------------------------------------------------------------------------------- 1 | # Generated with JReleaser 1.4.0 at 2023-01-28T20:40:45.870433537+01:00 2 | project: 3 | name: EqualsVerifier 4 | description: Makes testing equals and hashCode a one-liner 5 | longDescription: EqualsVerifier can be used in JUnit unit tests to verify whether the contract for the equals and hashCode methods is met. 6 | authors: 7 | - Jan Ouwens 8 | license: Apache-2.0 9 | links: 10 | homepage: https://jqno.nl/equalsverifier 11 | java: 12 | groupId: nl.jqno.equalsverifier 13 | version: 8 14 | inceptionYear: 2009 15 | 16 | release: 17 | github: 18 | owner: jqno 19 | tagName: equalsverifier-{{projectVersion}} 20 | changelog: 21 | enabled: true 22 | formatted: ALWAYS 23 | content: | 24 | For a list of changes in this version, see [CHANGELOG.md](https://github.com/jqno/equalsverifier/blob/main/CHANGELOG.md). 25 | 26 | signing: 27 | active: ALWAYS 28 | armored: true 29 | 30 | deploy: 31 | maven: 32 | mavenCentral: 33 | sonatype: 34 | active: ALWAYS 35 | url: https://central.sonatype.com/api/v1/publisher 36 | stagingRepositories: 37 | - target/staging-deploy 38 | -------------------------------------------------------------------------------- /video.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jqno/equalsverifier/4595cb5f97024d925cd6b915716ab04ca7e46d52/video.png --------------------------------------------------------------------------------