{"id":20373192,"url":"https://github.com/st235/assertion","last_synced_at":"2026-05-01T20:31:59.417Z","repository":{"id":57722970,"uuid":"122768977","full_name":"st235/Assertion","owner":"st235","description":"Do assertions wisely! 🎟","archived":false,"fork":false,"pushed_at":"2021-02-06T08:06:34.000Z","size":146,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-15T06:49:43.193Z","etag":null,"topics":["android","assertion-library","assertions","java","runtime"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/st235.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":"2018-02-24T18:46:38.000Z","updated_at":"2021-02-06T08:06:36.000Z","dependencies_parsed_at":"2022-09-26T21:50:15.660Z","dependency_job_id":null,"html_url":"https://github.com/st235/Assertion","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/st235%2FAssertion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FAssertion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FAssertion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/st235%2FAssertion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/st235","download_url":"https://codeload.github.com/st235/Assertion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241921836,"owners_count":20042763,"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":["android","assertion-library","assertions","java","runtime"],"created_at":"2024-11-15T01:17:03.211Z","updated_at":"2026-05-01T20:31:59.379Z","avatar_url":"https://github.com/st235.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.st235/assertion-utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.st235/assertion-utils)\n[![CircleCI](https://circleci.com/gh/st235/Assertion.svg?style=svg)](https://circleci.com/gh/st235/Assertion)\n\n# Assertion Util\n\nDo `assertions` wisely!\n\n## Installation\n\n__Important: library was migrated from JCenter to MavenCentral__ \n\nIt means that it may be necessary to add __mavenCentral__ repository to your repositories list\n\n```groovy\nallprojects {\n    repositories {\n        // your repositories\n\n        mavenCentral()\n    }\n}\n```\n\n- Maven\n```\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.st235\u003c/groupId\u003e\n  \u003cartifactId\u003eassertion-utils\u003c/artifactId\u003e\n  \u003cversion\u003eX.X.X\u003c/version\u003e\n  \u003ctype\u003epom\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n- Gradle\n```\nimplementation 'com.github.st235:assertion-utils:X.X.X'\n```\n**Note**: `compile` at the old versions of Gradle\n\n- Ivy\n```\n\u003cdependency org='com.github.st235' name='assertion-utils' rev='X.X.X'\u003e\n  \u003cartifact name='assertion-utils' ext='pom' /\u003e\n\u003c/dependency\u003e\n```\n\nP.S.: Check out latest version code in badge at the top of this page.\n\n## SetUp\n\nFirst of all, you should set up your assertion environment.\nUsually it happens in your Application class.\n\n```kotlin\nclass App: Application() {\n    override fun onCreate() {\n        super.onCreate()\n        Assert.setEnvironment(DefaultEnvironment(BuildConfig.DEBUG))\n    }\n}\n```\n\nThen you're able to use it in your code.\n\n```kotlin\n        when (calculateType()) {\n            A -\u003e Log.d(TAG, \"A\")\n            B -\u003e Log.d(TAG, \"B\")\n            else -\u003e {\n                // should fail only at production\n                Assert.assertFail(\"Unknown statement reached\")\n            }\n        }\n```\n\n## Environment\n\nThere is one default environment called `DefaultEnvironemt`. Its really easy to use - it accepts boolean flag, \nwhich means do assertion enabled in current build or not.\n\nUsage example:\n\n```kotlin\n    DefaultEnvironment(BuildConfig.DEBUG)\n```\n\nBut if u need more flexibility in environment set up, you're always able to inherit base class for all\nthe environments `AssertionEnvironment`\n\n```kotlin\nabstract class AssertionEnvironment {\n\n    abstract val isEnabled: Boolean\n\n    open fun fall(message: String?) {\n        throw AssertionException(message)\n    }\n}\n```\n\n**val isEnabled: Boolean** - switch on or off the assertion mechanism\n\n**fun fall(message: String?)** - assertion fails and environment calls this method to react properly. Default behavior\nwill throws `AssertionException`\n\n## Java\n\nThis util is backward compatible with java code. Use it as in examples below.\n\n```java\n    private static class DefaultEnvironment extends AssertionEnvironment {\n        @Override\n        public boolean isEnabled() {\n            return BuildConfig.DEBUG;\n        }\n    }\n\n    @Override\n    public void onCreate() {\n        Assert.setEnvironment(new DefaultEnvironment());\n    }\n\n    Assert.assertNull(\"Object must be null\", a);\n    Assert.assertNotNull(\"Object must be not null\", b);\n```\n\n## License\n\n```text\nMIT License\n\nCopyright (c) 2018 - present Alexander Dadukin\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst235%2Fassertion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fst235%2Fassertion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fst235%2Fassertion/lists"}