From bcb4a46315056968a353db1e642d738dbf0c7ee3 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Fri, 16 Aug 2024 13:16:33 +0530 Subject: [PATCH] Fixed the `JvmMockKGateway` error in mock deps. * Fixed the SearchStateTest test which sometimes failing. --- buildSrc/src/main/kotlin/Versions.kt | 2 +- .../core/search/viewmodel/SearchStateTest.kt | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 8063e8d4b..7acb846e7 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -38,7 +38,7 @@ object Versions { const val io_objectbox: String = "3.5.0" - const val io_mockk: String = "1.13.12" + const val io_mockk: String = "1.13.7" const val android_arch_lifecycle_extensions: String = "1.1.1" diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt index f5c7121f8..c474cbc4f 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/SearchStateTest.kt @@ -109,7 +109,7 @@ internal class SearchStateTest { val searchIteratorWrapper: SuggestionIteratorWrapper = mockk() val entryWrapper: SuggestionItemWrapper = mockk() - every { suggestionSearchWrapper.estimatedMatches } returns 500 + every { suggestionSearchWrapper.estimatedMatches } returns 100 every { searchIteratorWrapper.hasNext() } returnsMany listOf(true, false) every { searchIteratorWrapper.next() } returns entryWrapper every { entryWrapper.title } returns "Result" @@ -125,18 +125,19 @@ internal class SearchStateTest { } job.cancelAndJoin() - val job1 = launch(Dispatchers.IO) { - list1 = searchState.getVisibleResults(0) - } - // test the coroutine job is cancelled properly assertThat(job.isCancelled).isTrue assertThat(list?.size).isEqualTo(0) - // test the second job is successfully return the data - assertThat(job1.isCompleted).isTrue - assertThat(list1?.size).isEqualTo(1) - assertThat(list1?.get(0)?.url).isEqualTo("path") - assertThat(list1?.get(0)?.value).isEqualTo("Result") + val job1 = launch(Dispatchers.IO) { + list1 = searchState.getVisibleResults(0) + } + job1.invokeOnCompletion { + // test the second job is successfully return the data + assertThat(job1.isCompleted).isTrue + assertThat(list1?.size).isEqualTo(1) + assertThat(list1?.get(0)?.url).isEqualTo("path") + assertThat(list1?.get(0)?.value).isEqualTo("Result") + } } }