{"id":16489373,"url":"https://github.com/michaelbukachi/mockkcallback","last_synced_at":"2025-05-02T17:30:24.156Z","repository":{"id":86011639,"uuid":"142262527","full_name":"michaelbukachi/MockkCallback","owner":"michaelbukachi","description":"A tutorial on testing Java 8 callbacks using kotlin","archived":false,"fork":false,"pushed_at":"2018-07-31T05:19:54.000Z","size":138,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T03:42:35.007Z","etag":null,"topics":["android","kotlin","mocking","mockk","testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/michaelbukachi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2018-07-25T07:17:28.000Z","updated_at":"2021-10-16T18:48:21.000Z","dependencies_parsed_at":"2023-03-04T21:31:05.582Z","dependency_job_id":null,"html_url":"https://github.com/michaelbukachi/MockkCallback","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/michaelbukachi%2FMockkCallback","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelbukachi%2FMockkCallback/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelbukachi%2FMockkCallback/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/michaelbukachi%2FMockkCallback/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/michaelbukachi","download_url":"https://codeload.github.com/michaelbukachi/MockkCallback/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252080734,"owners_count":21691563,"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","kotlin","mocking","mockk","testing"],"created_at":"2024-10-11T13:44:02.754Z","updated_at":"2025-05-02T17:30:24.145Z","avatar_url":"https://github.com/michaelbukachi.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Testing Asynchronous Callbacks in Kotlin\n\nCode snippet:\n```\n\nclass ConsumerTest {\n\n    @MockK(relaxUnitFun = true) // In order to avoid the strict check by Mockk, a relaxed mock is required\n    lateinit var task: BackgroundTask\n\n    lateinit var consumer: Consumer\n\n    lateinit var spyConsumer: Consumer\n\n    val callbackSlot = slot\u003cCallback\u003e()\n\n    @Before\n    fun setup() {\n        MockKAnnotations.init(this)\n        consumer = Consumer(task)\n        spyConsumer = spyk(consumer, recordPrivateCalls = true)\n    }\n\n    @Test\n    fun `test success`() {\n        // Handle what happens when task.doBackground... is called\n        // Capture callback and trigger it with the necessary data\n        every { task.doBackground(capture(callbackSlot)) } answers {\n            callbackSlot.captured.onDone(true, null)\n        }\n\n        spyConsumer.doBackgroundTask()\n\n        verifyOrder {\n            spyConsumer[\"printStarting\"]()\n            spyConsumer[\"printSuccess\"]()\n        }\n    }\n\n    @Test\n    fun `test failure`() {\n        every { task.doBackground(capture(callbackSlot)) } answers {\n            callbackSlot.captured.onDone(false, null)\n        }\n\n        spyConsumer.doBackgroundTask()\n\n        verifyOrder {\n            spyConsumer[\"printStarting\"]()\n            spyConsumer[\"printFailed\"]()\n        }\n    }\n}\n\n``` \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelbukachi%2Fmockkcallback","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmichaelbukachi%2Fmockkcallback","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmichaelbukachi%2Fmockkcallback/lists"}