{"id":21175244,"url":"https://github.com/alb-i986/assert-retry","last_synced_at":"2025-03-14T18:21:51.429Z","repository":{"id":55561674,"uuid":"92556417","full_name":"alb-i986/assert-retry","owner":"alb-i986","description":"An extension to JUnit/Hamcrest providing assertions with tolerance, featuring a retry mechanism.","archived":false,"fork":false,"pushed_at":"2023-12-05T22:30:15.000Z","size":151,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-21T11:25:45.566Z","etag":null,"topics":["assertions","hamcrest","junit","retry","testing"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alb-i986.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-26T23:47:06.000Z","updated_at":"2020-12-23T00:47:00.000Z","dependencies_parsed_at":"2022-08-15T03:11:03.390Z","dependency_job_id":null,"html_url":"https://github.com/alb-i986/assert-retry","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alb-i986%2Fassert-retry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alb-i986%2Fassert-retry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alb-i986%2Fassert-retry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alb-i986%2Fassert-retry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alb-i986","download_url":"https://codeload.github.com/alb-i986/assert-retry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243624087,"owners_count":20321029,"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":["assertions","hamcrest","junit","retry","testing"],"created_at":"2024-11-20T16:57:38.678Z","updated_at":"2025-03-14T18:21:51.408Z","avatar_url":"https://github.com/alb-i986.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Assert Retry\n\nAn extension to JUnit/Hamcrest providing _assertions with tolerance_, featuring a __retry__ mechanism.\n\n\n## Motivation\n\nAFAIK there are already two libraries out there resolving the same problem this library is addressing:\n \n- [Awaitility](https://github.com/awaitility/awaitility)\n- [guava-retrying](https://github.com/rholder/guava-retrying)\n\nAwaitility in particular looks pretty good indeed.\n\nThe added value of `assert-retry` is that it is integrated with Hamcrest's `assertThat` assertions.\n\nWhat I love about Hamcrest assertions is the valuable feedback they provide to the user when they fail.\n\n\n## Example of usage\n\nSay that we have a JMS queue, and we need to verify that a message with body \"expected content\" is published on the queue.\nGiven the async nature of the system, we need to employ a bit of tolerance in our assertions.\n\n    import static me.alb_i986.testing.assertions.retry.RetryMatcher.eventually;\n    import static org.hamcrest.Matchers.containsString;\n    import static org.junit.Assert.assertThat;\n      \n    MessageConsumer consumer = session.createConsumer(queue);\n    connection.start();\n    Supplier\u003cString\u003e messageText = new Supplier\u003c\u003e() {\n        @Override\n        public String get() throws JMSException {\n            TextMessage m = (TextMessage) consumer.receiveNoWait();  // polling for messages, non blocking\n            return m == null ? null : m.getText();\n        }\n    };\n    assertThat(messageText, eventually(containsString(\"expected content\"),\n            RetryConfig.builder()\n                .timeoutAfter(Duration.ofSeconds(60))\n                .sleepFor(Duration.ofSeconds(5))\n                .retryOnException(JMSException.class)\n    ));\n\nThe first few lines set up the Supplier of actual values, which will poll the message queue for messages.\n\nThen we have our assertion.\nIn this example it is asserting that the expected text message will be received within 60 seconds.\nAfter each failing attempt, it will wait for 5s, and then it will try again.\n\nIf `consumer.receiveNoWait()` throws a `JMSException`, the assertion will be re-tried,\nas if it returned a non-matching value.\n\nFinally, the assertion will timeout after 60s, and an AssertionError similar to the following will be thrown:\n\n       java.lang.AssertionError:\n       Expected: supplied value to *eventually* match a string containing \"expected content\" within 60s\n           but: The timeout was reached and none of the actual values matched\n                Actual values (in order of appearance):\n                 - \"some content\"\n                 - thrown javax.jms.MessageFormatException: Blah blah\n                 - \"some other content\"\n\nFor more info, please check the javadoc of `RetryMatcher#eventually`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falb-i986%2Fassert-retry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falb-i986%2Fassert-retry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falb-i986%2Fassert-retry/lists"}