{"id":17197686,"url":"https://github.com/dmcg/k-sera","last_synced_at":"2025-04-13T20:51:15.262Z","repository":{"id":144531590,"uuid":"77993361","full_name":"dmcg/k-sera","owner":"dmcg","description":"A JMock wrapper for Kotlin","archived":false,"fork":false,"pushed_at":"2017-01-04T08:08:09.000Z","size":30,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T11:13:33.190Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","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/dmcg.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-01-04T07:44:12.000Z","updated_at":"2022-10-03T15:41:56.000Z","dependencies_parsed_at":"2023-07-10T21:32:09.793Z","dependency_job_id":null,"html_url":"https://github.com/dmcg/k-sera","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcg%2Fk-sera","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcg%2Fk-sera/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcg%2Fk-sera/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dmcg%2Fk-sera/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dmcg","download_url":"https://codeload.github.com/dmcg/k-sera/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248782278,"owners_count":21160716,"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":[],"created_at":"2024-10-15T01:57:04.990Z","updated_at":"2025-04-13T20:51:15.236Z","avatar_url":"https://github.com/dmcg.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nK-Sera\n=====\n\nA JMock wrapper for Kotlin.\n\n[KSeraExampleTests](src/test/java/com/oneeyedmen/kSera/KSeraExampleTests.kt)\nshows how to write a test.\n\n```kotlin\nclass KSeraExampleTests {\n\n    // Create a mockery using the usual JMock rule\n    @Rule @JvmField val mockery = JUnitRuleMockery()\n\n    // and a mock from the mockery\n    val charSequence = mockery.mock\u003cCharSequence\u003e()\n\n    @Test fun `expect a call to a mock via the mockery`() {\n        mockery.expecting {\n            oneOf(charSequence).length\n        }\n        // in this case JMock returns a default value\n        assertEquals(0, charSequence.length)\n    }\n\n    @Test fun `you can specify a (type-checked) return value for a call`() {\n        mockery.expecting {\n            oneOf(charSequence).length.which will returnValue(42)\n        }\n        assertEquals(42, charSequence.length)\n\n        // oneOf(charSequence).length.which will returnValue(\"banana\") doesn't compile\n    }\n\n    @Test fun `simulate failures with throwException`() {\n        mockery.expecting {\n            oneOf(charSequence).length.which will throwException(RuntimeException(\"deliberate\"))\n        }\n        assertFails {\n            charSequence.length\n        }\n    }\n\n    @Test fun `special operators work well`() {\n        mockery.expecting {\n            allowing(charSequence)[0].which will returnValue('*')\n        }\n        assertEquals('*', charSequence.get(0))\n    }\n\n    @Test fun `match parameters with Hamkrest`() {\n        mockery.expecting {\n            allowing(charSequence)[with(lessThan(0))].which will returnValue('-')\n            allowing(charSequence)[with(anything)].which will returnValue('+')\n        }\n        assertEquals('-', charSequence.get(-1))\n        assertEquals('+', charSequence.get(99))\n    }\n\n    @Test fun `which-will can take a block and access the call invocation`() {\n        mockery.expecting {\n            allowing(charSequence)[with(anything)].which will { invocation -\u003e\n                (invocation.getParameter(0) as Int).toChar()\n            }\n        }\n        assertEquals(' ', charSequence[32])\n        assertEquals('A', charSequence[65])\n    }\n\n    @Test fun `you can mock functions too`() {\n        val f = mockery.mock\u003c(Any?) -\u003e String\u003e()\n        mockery.expecting {\n            allowing(f).invoke(with(anything)).which will returnValue(\"banana\")\n        }\n        assertEquals(\"banana\", f(\"ignored\"))\n    }\n\n    // Shall we play a game?\n\n    val controlPanel = Panel(\n        mockery.mock\u003cKey\u003e(\"key1\"),\n        mockery.mock\u003cKey\u003e(\"key2\"),\n        mockery.mock\u003cMissile\u003e())\n\n\n    @Test fun `block syntax for expecting-during-verify`() =\n        mockery {\n            expecting {\n                allowing(controlPanel.key1).isTurned.which will returnValue(true)\n                allowing(controlPanel.key2).isTurned.which will returnValue(true)\n            }\n            during {\n                controlPanel.pressButton()\n            }\n            verify {\n                oneOf(controlPanel.missile).launch()\n            }\n        }\n\n    @Test fun `given-that allows property references`() =\n        mockery {\n            given {\n                that(controlPanel.key1, Key::isTurned).isProperty withValue (true)\n                that(controlPanel.key2, Key::isTurned).isProperty withValue (false)\n            }\n            during {\n                controlPanel.pressButton()\n            }\n            verify {\n                never(controlPanel.missile).launch()\n            }\n        }\n\n}\n```\n\nk-sera is available at Maven central.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmcg%2Fk-sera","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdmcg%2Fk-sera","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdmcg%2Fk-sera/lists"}