{"id":22907435,"url":"https://github.com/oswaldobapvicjr/junit-utils","last_synced_at":"2025-08-30T22:14:01.083Z","repository":{"id":46269554,"uuid":"251409126","full_name":"oswaldobapvicjr/junit-utils","owner":"oswaldobapvicjr","description":"Common utilities for working with JUnit","archived":false,"fork":false,"pushed_at":"2025-05-05T04:45:15.000Z","size":180,"stargazers_count":18,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T05:31:50.881Z","etag":null,"topics":["assertion","instantiation","java","junit","junit-utils","testing","testing-tool","unit-testing"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oswaldobapvicjr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-03-30T19:34:10.000Z","updated_at":"2025-05-05T04:45:01.000Z","dependencies_parsed_at":"2024-01-28T05:19:50.075Z","dependency_job_id":"ff310e00-7e14-47d7-bcc2-86fb9c28a1e5","html_url":"https://github.com/oswaldobapvicjr/junit-utils","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oswaldobapvicjr%2Fjunit-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oswaldobapvicjr%2Fjunit-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oswaldobapvicjr%2Fjunit-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oswaldobapvicjr%2Fjunit-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oswaldobapvicjr","download_url":"https://codeload.github.com/oswaldobapvicjr/junit-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253155381,"owners_count":21862688,"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","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":["assertion","instantiation","java","junit","junit-utils","testing","testing-tool","unit-testing"],"created_at":"2024-12-14T03:15:12.337Z","updated_at":"2025-08-30T22:14:01.076Z","avatar_url":"https://github.com/oswaldobapvicjr.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![junit-utils logo](resources/junit-utils_logo.svg)\n\n[![Java 8+](https://img.shields.io/badge/Java-8%2B-blue.svg)](https://openjdk.java.net/)\n[![Known Vulnerabilities](https://snyk.io/test/github/oswaldobapvicjr/junit-utils/badge.svg)](https://snyk.io/test/github/oswaldobapvicjr/junit-utils)\n[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/oswaldobapvicjr/junit-utils/maven.yml?branch=master\u0026label=build)](https://github.com/oswaldobapvicjr/junit-utils/actions/workflows/maven.yml)\n[![Coverage](https://img.shields.io/codecov/c/github/oswaldobapvicjr/junit-utils)](https://codecov.io/gh/oswaldobapvicjr/junit-utils)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/net.obvj/junit-utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/net.obvj/junit-utils)\n[![Javadoc](https://javadoc.io/badge2/net.obvj/junit-utils/javadoc.svg)](https://javadoc.io/doc/net.obvj/junit-utils)\n\nCommon utilities for working with JUnit:\n\n- assertion of **exceptions**, as well as exception details, such as message and cause\n- assertion of strings contents\n- testing that a class **cannot be instantiated**\n\n----\n\n## Examples\n\n\u003e **Note:** Consider the following static import declarations for readability:\n\n```java\nimport static net.obvj.junit.utils.matchers.AdvancedMatchers.*;\nimport static org.hamcrest.CoreMatchers.*;\nimport static org.hamcrest.MatcherAssert.assertThat;\n```\n\n### Asserting exceptions\n\nThe following assertion is true if the examined method throws a NullPointerException:\n\n```java\nassertThat(() -\u003e myObject.doStuff(null),\n        throwsException(NullPointerException.class));\n```\n\nTo test the exception **message**, add `withMessageContaining` ...\n\n```java\nassertThat(() -\u003e myObject.doStuff(null),\n        throwsException(NullPointerException.class)\n            .withMessageContaining(\"ERR-120008\"));\n```\n\n... or combine a String matcher:\n\n````java\nassertThat(() -\u003e agent.loadSchemaFile(\"bad-schema.xsd\"),\n        throwsException(AgentConfigurationException.class)\n            .withMessage(\n                either(startsWith(\"ERR-0001\"))\n                    .or(containsAny(\"invalid schema\").ignoreCase())));\n````\n\nIf required, you can also test the exception **cause**:\n\n```java\nassertThat(() -\u003e myObject.doStuff(null),\n        throwsException(MyException.class).withMessageContaining(\"ERR-120008\")\n            .withCause(NullPointerException.class));\n```\n\nIncluding cause details:\n\n```java\nassertThat(() -\u003e myObject.doStuff(null),\n        throwsException(MyException.class).withMessageContaining(\"ERR-120008\")\n            .withCause(\n                exception(NullPointerException.class)\n                    .withMessage(\"stuff cannot be null\")));\n```\n\nAnd more:\n\n```java\nassertThat(() -\u003e httpClient.post(request),\n        throwsException(HttpException.class)\n            .with(HttpException::getStatusCode, equalTo(400));\n```\n \n\n### Testing that instantiation is not allowed\n\nThe following assertion is particularly useful for utility classes:\n\n```java\nassertThat(TestUtils.class, instantiationNotAllowed());\n```\n\n A matching class shall have all constructors declared as private and throw an exception inside the default constructor.\n\n### Testing the contents of a string\n\nThe following examples represent some successful assertions using the Advanced String matcher:\n\n```java\nassertThat(\"The quick brown fox jumps over the lazy dog\", containsAll(\"dog\", \"fox\"));\nassertThat(\"The quick brown fox jumps over the lazy dog\", containsAny(\"FOX\", \"dragon\").ignoreCase());\nassertThat(\"The quick brown fox jumps over the lazy dog\", containsNone(\"centaur\"));\nassertThat(\"The quick brown fox jumps over the lazy dog\", containsAllInSequence(\"fox\", \"dog\"));\n```\n\n### Testing numbers\n\nSometimes, it's more meaningful to check whether a number is positive or negative than testing the value itself, especially in situations where the exact value is unpredictable:\n\n```java\nassertThat(stopwatch.elapsedTime(),           isPositive());\nassertThat(duration.compareTo(otherDuration), isNegative());\n```\n\n----\n\n## How to include it\n\nIf you are using Maven, add **junit-utils** as a dependency in your pom.xml file:\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.obvj\u003c/groupId\u003e\n    \u003cartifactId\u003ejunit-utils\u003c/artifactId\u003e\n    \u003cversion\u003e1.9.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nIf you use other dependency management systems (such as Gradle, Grape, Ivy, etc.) click [here](https://maven-badges.herokuapp.com/maven-central/net.obvj/junit-utils).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foswaldobapvicjr%2Fjunit-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foswaldobapvicjr%2Fjunit-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foswaldobapvicjr%2Fjunit-utils/lists"}