From 7116c8e0c31894fdd1d62485810482cd893e78df Mon Sep 17 00:00:00 2001 From: Nik Clayton Date: Thu, 1 Feb 2024 15:50:40 +0100 Subject: [PATCH] test: Mock searchSync to prevent crash in ComposeActivityTest (#404) Without the mock the code-under-test was getting a null value where none should have been possible, and crashing. --- .../app/pachli/components/compose/ComposeActivityTest.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt b/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt index 2237a8ebf..528e4ad17 100644 --- a/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt +++ b/app/src/test/java/app/pachli/components/compose/ComposeActivityTest.kt @@ -29,6 +29,7 @@ import app.pachli.core.navigation.ComposeActivityIntent.ComposeOptions import app.pachli.core.network.model.Account import app.pachli.core.network.model.InstanceConfiguration import app.pachli.core.network.model.InstanceV1 +import app.pachli.core.network.model.SearchResult import app.pachli.core.network.model.StatusConfiguration import app.pachli.core.network.retrofit.MastodonApi import app.pachli.core.testing.rules.lazyActivityScenarioRule @@ -47,6 +48,8 @@ import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith +import org.mockito.kotlin.any +import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.doAnswer import org.mockito.kotlin.doReturn import org.mockito.kotlin.reset @@ -96,6 +99,9 @@ class ComposeActivityTest { } } } + onBlocking { searchSync(any(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull(), anyOrNull()) } doReturn NetworkResult.success( + SearchResult(emptyList(), emptyList(), emptyList()), + ) } accountManager.addAccount(