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.
This commit is contained in:
Nik Clayton 2024-02-01 15:50:40 +01:00 committed by GitHub
parent ce21b3b9f8
commit 7116c8e0c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 0 deletions

View File

@ -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(