{"id":23282772,"url":"https://github.com/itsallcode/hamcrest-auto-matcher","last_synced_at":"2025-10-08T10:57:10.830Z","repository":{"id":80229547,"uuid":"57589747","full_name":"itsallcode/hamcrest-auto-matcher","owner":"itsallcode","description":"Automatic hamcrest matcher for model classes","archived":false,"fork":false,"pushed_at":"2024-11-15T20:11:11.000Z","size":484,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-08-21T13:46:26.429Z","etag":null,"topics":["hamcrest","hamcrest-matchers","java","junit","matcher"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itsallcode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-01T07:53:52.000Z","updated_at":"2024-11-15T20:11:14.000Z","dependencies_parsed_at":"2024-11-16T00:15:32.464Z","dependency_job_id":null,"html_url":"https://github.com/itsallcode/hamcrest-auto-matcher","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/itsallcode/hamcrest-auto-matcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsallcode%2Fhamcrest-auto-matcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsallcode%2Fhamcrest-auto-matcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsallcode%2Fhamcrest-auto-matcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsallcode%2Fhamcrest-auto-matcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itsallcode","download_url":"https://codeload.github.com/itsallcode/hamcrest-auto-matcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itsallcode%2Fhamcrest-auto-matcher/sbom","scorecard":{"id":497356,"data":{"date":"2025-08-11","repo":{"name":"github.com/itsallcode/hamcrest-auto-matcher","commit":"719b73593b31dbbb037b4eae1ab107ddcd36f954"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.5,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/18 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":9,"reason":"binaries present in source code","details":["Warn: binary detected: gradle/wrapper/gradle-wrapper.jar:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'contents' permission set to 'read': .github/workflows/build.yml:23","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql-analysis.yml:14","Warn: jobLevel 'contents' permission set to 'write': .github/workflows/release.yml:22","Warn: no topLevel permission defined: .github/workflows/build.yml:1","Warn: no topLevel permission defined: .github/workflows/codeql-analysis.yml:1","Warn: no topLevel permission defined: .github/workflows/release.yml:1"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/build.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/build.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/build.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/codeql-analysis.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/codeql-analysis.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/codeql-analysis.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/codeql-analysis.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/codeql-analysis.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql-analysis.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/codeql-analysis.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:25: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/release.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/release.yml/main?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/release.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/itsallcode/hamcrest-auto-matcher/release.yml/main?enable=pin","Info:   0 out of  10 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   3 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/release.yml:13"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Branch-Protection","score":4,"reason":"branch protection is not maximal on development and all release branches","details":["Info: 'allow deletion' disabled on branch 'main'","Info: 'force pushes' disabled on branch 'main'","Warn: 'branch protection settings apply to administrators' is disabled on branch 'main'","Warn: 'stale review dismissal' is disabled on branch 'main'","Warn: branch 'main' does not require approvers","Warn: codeowners review is required - but no codeowners file found in repo","Info: 'last push approval' is required to merge on branch 'main'","Warn: 'up-to-date branches' is disabled on branch 'main'","Info: status check found to merge onto on branch 'main'","Info: PRs are required in order to make changes on branch 'main'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":7,"reason":"SAST tool detected but not run on all commits","details":["Info: SAST configuration detected: CodeQL","Warn: 7 commits out of 25 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-19T20:48:23.073Z","repository_id":80229547,"created_at":"2025-08-19T20:48:23.073Z","updated_at":"2025-08-19T20:48:23.073Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278931652,"owners_count":26070789,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hamcrest","hamcrest-matchers","java","junit","matcher"],"created_at":"2024-12-20T00:29:36.931Z","updated_at":"2025-10-08T10:57:10.813Z","avatar_url":"https://github.com/itsallcode.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hamcrest-auto-matcher\n\nAutomatic hamcrest matcher for model classes for Java 11\n\n[![Build](https://github.com/itsallcode/hamcrest-auto-matcher/actions/workflows/build.yml/badge.svg)](https://github.com/itsallcode/hamcrest-auto-matcher/actions/workflows/build.yml)\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=org.itsallcode%3Ahamcrest-auto-matcher\u0026metric=alert_status)](https://sonarcloud.io/dashboard?id=org.itsallcode%3Ahamcrest-auto-matcher)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=org.itsallcode%3Ahamcrest-auto-matcher\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=org.itsallcode%3Ahamcrest-auto-matcher)\n[![Maven Central](https://img.shields.io/maven-central/v/org.itsallcode/hamcrest-auto-matcher)](https://search.maven.org/artifact/org.itsallcode/hamcrest-auto-matcher)\n\n## Why use `hamcrest-auto-matcher`?\n\nWriting a Hamcrest matcher for your model classes by extending [`TypeSafeDiagnosingMatcher`](https://hamcrest.org/JavaHamcrest/javadoc/3.0/org/hamcrest/TypeSafeDiagnosingMatcher.html) is a good idea, because it gives you a readable diff of actual and expected property values. But doing it by hand is tedious and hard to get right, especially for classes with many properties:\n* It is easy to make mistakes in the [`matches()`](https://hamcrest.org/JavaHamcrest/javadoc/3.0/org/hamcrest/TypeSafeDiagnosingMatcher.html#matches%28java.lang.Object%29) method.\n* It requires lot's of boiler plate code.\n* Good layout of actual and expected property values is hard to get right.\n* Each property occurs in multiple places which violates the [DRY](https://en.wikipedia.org/wiki/Don't_repeat_yourself) principle.\n\n## Project Information\n\n* [Changelog](CHANGELOG.md)\n* Requirements\n  * Java 11\n  * Hamcrest 3.0\n\n## How to use `hamcrest-auto-matcher` in your project\n\n### Setup dependencies\n\n#### Gradle\n\n```groovy\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    testImplementation 'org.itsallcode:hamcrest-auto-matcher:0.8.2'\n}\n```\n\n#### Maven\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.itsallcode\u003c/groupId\u003e\n    \u003cartifactId\u003ehamcrest-auto-matcher\u003c/artifactId\u003e\n    \u003cversion\u003e0.8.2\u003c/version\u003e\n    \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n### Using [`AutoMatcher`](src/main/java/org/itsallcode/matcher/auto/AutoMatcher.java)\n\nAssume you have two model classes [`DemoModel`](src/test/java/org/itsallcode/matcher/model/DemoModel.java) and [`DemoAttribute`](src/test/java/org/itsallcode/matcher/model/DemoAttribute.java):\n\n```java\npublic class DemoModel {\n    private final int id;\n    private final String name;\n    private final DemoAttribute attr;\n    private final List\u003cDemoModel\u003e children;\n    private final String[] stringArray;\n    private final Long longVal;\n\n    public DemoModel(int id, String name, Long longVal, DemoAttribute attr, String[] stringArray,\n            List\u003cDemoModel\u003e children) {\n        this.id = id;\n        this.name = name;\n        this.longVal = longVal;\n        this.attr = attr;\n        this.stringArray = stringArray;\n        this.children = children;\n    }\n\n    public int getId() {\n        return id;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public DemoAttribute getAttr() {\n        return attr;\n    }\n\n    public List\u003cDemoModel\u003e getChildren() {\n        return children;\n    }\n\n    public String[] getStringArray() {\n        return stringArray;\n    }\n\n    public Long getLongVal() {\n        return longVal;\n    }\n\n    @Override\n    public String toString() {\n        return \"DemoModel [id=\" + id + \", name=\" + name + \", attr=\" + attr + \", children=\" + children + \", stringArray=\"\n                + Arrays.toString(stringArray) + \", longVal=\" + longVal + \"]\";\n    }\n}\n\npublic class DemoAttribute {\n    private final String value;\n\n    public DemoAttribute(String value) {\n        this.value = value;\n    }\n\n    public String getValue() {\n        return value;\n    }\n\n    @Override\n    public String toString() {\n        return \"DemoAttribute [value=\" + value + \"]\";\n    }\n}\n```\n\nUse [`AutoMatcher.equalTo()`](src/main/java/org/itsallcode/matcher/auto/AutoMatcher.java) to create a matcher for your expected model instance. This will use reflection to determine expected property values based on getter methods:\n\n```java\nimport org.itsallcode.matcher.auto.AutoMatcher;\n\nDemoModel expected = ...;\nDemoModel actual = ...;\nassertThat(actual, AutoMatcher.equalTo(expected));\n```\n\nExample mismatch report:\n```\nExpected: {id=\u003c4711\u003e, longVal=null, name=\"name1\", attr=null, stringArray=null, children=null}\n     but: {longVal was \u003c42L\u003e}\n```\n\n#### Property Detection\n\nAutoMatcher creates properties for methods matching the following criteria:\n\n* Visibility: `public`\n* Name: starts with `get` or `is`\n* Signature: not `void` and no arguments\n* Not one of the built-in methods `getClass()`, `getProtectionDomain()`, `getClassLoader()`, `getURLs()`\n\n### Using [`ConfigurableMatcher`](src/main/java/org/itsallcode/matcher/config/ConfigurableMatcher.java)\nIf `AutoMatcher` does not work for your model classes, you can still use [`ConfigurableMatcher`](src/main/java/org/itsallcode/matcher/config/ConfigurableMatcher.java) and [`MatcherConfig`](src/main/java/org/itsallcode/matcher/config/MatcherConfig.java) which allows you to specify properties and custom matchers explicitly but is much easier to use than `TypeSafeDiagnosingMatcher`.\n\n```java\nimport org.itsallcode.matcher.config.MatcherConfig;\nimport org.itsallcode.matcher.config.ConfigurableMatcher;\n\npublic class DemoModelMatcher {\n    public static Matcher\u003cDemoModel\u003e equalTo(DemoModel expected) {\n        final MatcherConfig\u003cDemoModel\u003e config = MatcherConfig.builder(expected)\n                .addEqualsProperty(\"id\", DemoModel::getId)\n                .addEqualsProperty(\"longVal\", DemoModel::getLongVal)\n                .addEqualsProperty(\"name\", DemoModel::getName)\n                .addProperty(\"attr\", DemoModel::getAttr, DemoAttributeMatcher::equalTo)\n                .addEqualsProperty(\"stringArray\", DemoModel::getStringArray)\n                .addIterableProperty(\"children\", DemoModel::getChildren, DemoModelMatcher::equalTo)\n                .build();\n        return new ConfigurableMatcher\u003c\u003e(config);\n    }\n}\n```\nAlso see [`DemoModelMatcher`](src/test/java/org/itsallcode/matcher/model/DemoModelMatcher.java) as an example.\n\n## Development\n\n```sh\ngit clone https://github.com/itsallcode/hamcrest-auto-matcher.git\ncd hamcrest-auto-matcher\n./gradlew check\n# Test report: build/reports/tests/index.html\n```\n\n### Using eclipse\n\nImport into eclipse using [buildship](https://projects.eclipse.org/projects/tools.buildship).\n\n### Run sonar analysis\n\n```sh\n./gradlew clean sonar --info -Dsonar.token=[token]\n```\n\n### Check for dependency updates\n\n```sh\n./gradlew dependencyUpdates\n```\n\n### Test Coverage\n\nTo calculate and view test coverage:\n\n```sh\n./gradlew check jacocoTestReport\nopen build/reports/jacoco/test/html/index.html\n```\n\n### Publish to Maven Central\n\n#### Preparations\n\n1. Checkout the `main` branch, create a new branch.\n2. Update version number in `build.gradle` and `README.md`.\n3. Add changes in new version to `CHANGELOG.md`.\n4. Commit and push changes.\n5. Create a new pull request, have it reviewed and merged to `main`.\n\n#### Perform the Release\n\n1. Start the release workflow\n  * Run command `gh workflow run release.yml --repo itsallcode/hamcrest-auto-matcher --ref main`\n  * or go to [GitHub Actions](https://github.com/itsallcode/hamcrest-auto-matcher/actions/workflows/release.yml) and start the `release.yml` workflow on branch `main`.\n2. Update title and description of the newly created [GitHub release](https://github.com/itsallcode/hamcrest-auto-matcher/releases).\n3. After some time the release will be available at [Maven Central](https://repo1.maven.org/maven2/org/itsallcode/hamcrest-auto-matcher/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsallcode%2Fhamcrest-auto-matcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitsallcode%2Fhamcrest-auto-matcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitsallcode%2Fhamcrest-auto-matcher/lists"}