From 0356b873e93e2381cf17bc23caf52a7020ebd230 Mon Sep 17 00:00:00 2001 From: saeedishayan76 Date: Mon, 2 Sep 2024 21:57:24 +0330 Subject: [PATCH 1/4] change collectJob to backgroundScope coroutine --- .../bookmarks/BookmarksViewModelTest.kt | 6 +- .../feature/foryou/ForYouViewModelTest.kt | 70 ++++++------------- .../interests/InterestsViewModelTest.kt | 11 +-- .../feature/search/SearchViewModelTest.kt | 19 ++--- .../feature/settings/SettingsViewModelTest.kt | 4 +- .../feature/topic/TopicViewModelTest.kt | 15 ++-- 6 files changed, 36 insertions(+), 89 deletions(-) diff --git a/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt b/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt index 037e9db647..ff8e6946fb 100644 --- a/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt +++ b/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt @@ -64,7 +64,7 @@ class BookmarksViewModelTest { @Test fun oneBookmark_showsInFeed() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.feedUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedUiState.collect() } newsRepository.sendNewsResources(newsResourcesTestData) userDataRepository.setNewsResourceBookmarked(newsResourcesTestData[0].id, true) @@ -72,12 +72,11 @@ class BookmarksViewModelTest { assertIs(item) assertEquals(item.feed.size, 1) - collectJob.cancel() } @Test fun oneBookmark_whenRemoving_removesFromFeed() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.feedUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedUiState.collect() } // Set the news resources to be used by this test newsRepository.sendNewsResources(newsResourcesTestData) // Start with the resource saved @@ -89,6 +88,5 @@ class BookmarksViewModelTest { assertIs(item) assertEquals(item.feed.size, 0) - collectJob.cancel() } } diff --git a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index eece140aca..5db2a76f9e 100644 --- a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt +++ b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -98,9 +98,8 @@ class ForYouViewModelTest { @Test fun stateIsLoadingWhenFollowedTopicsAreLoading() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } topicsRepository.sendTopics(sampleTopics) @@ -110,30 +109,25 @@ class ForYouViewModelTest { ) assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value) - collectJob1.cancel() - collectJob2.cancel() } @Test fun stateIsLoadingWhenAppIsSyncingWithNoInterests() = runTest { syncManager.setSyncing(true) - val collectJob = - launch(UnconfinedTestDispatcher()) { viewModel.isSyncing.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.isSyncing.collect() } assertEquals( true, viewModel.isSyncing.value, ) - collectJob.cancel() } @Test fun onboardingStateIsLoadingWhenTopicsAreLoading() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } userDataRepository.setFollowedTopicIds(emptySet()) @@ -142,16 +136,13 @@ class ForYouViewModelTest { viewModel.onboardingUiState.value, ) assertEquals(NewsFeedUiState.Success(emptyList()), viewModel.feedState.value) - - collectJob1.cancel() - collectJob2.cancel() } @Test fun onboardingIsShownWhenNewsResourcesAreLoading() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } topicsRepository.sendTopics(sampleTopics) userDataRepository.setFollowedTopicIds(emptySet()) @@ -202,16 +193,12 @@ class ForYouViewModelTest { ), viewModel.feedState.value, ) - - collectJob1.cancel() - collectJob2.cancel() } @Test fun onboardingIsShownAfterLoadingEmptyFollowedTopics() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } topicsRepository.sendTopics(sampleTopics) userDataRepository.setFollowedTopicIds(emptySet()) @@ -264,15 +251,12 @@ class ForYouViewModelTest { viewModel.feedState.value, ) - collectJob1.cancel() - collectJob2.cancel() } @Test fun onboardingIsNotShownAfterUserDismissesOnboarding() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } topicsRepository.sendTopics(sampleTopics) @@ -300,15 +284,13 @@ class ForYouViewModelTest { viewModel.feedState.value, ) - collectJob1.cancel() - collectJob2.cancel() + } @Test fun topicSelectionUpdatesAfterSelectingTopic() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } topicsRepository.sendTopics(sampleTopics) userDataRepository.setFollowedTopicIds(emptySet()) @@ -352,16 +334,12 @@ class ForYouViewModelTest { ), viewModel.feedState.value, ) - - collectJob1.cancel() - collectJob2.cancel() } @Test fun topicSelectionUpdatesAfterUnselectingTopic() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } topicsRepository.sendTopics(sampleTopics) userDataRepository.setFollowedTopicIds(emptySet()) @@ -416,16 +394,12 @@ class ForYouViewModelTest { ), viewModel.feedState.value, ) - - collectJob1.cancel() - collectJob2.cancel() } @Test fun newsResourceSelectionUpdatesAfterLoadingFollowedTopics() = runTest { - val collectJob1 = - launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } - val collectJob2 = launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } val followedTopicIds = setOf("1") val userData = emptyUserData.copy( @@ -461,14 +435,11 @@ class ForYouViewModelTest { viewModel.feedState.value, ) - collectJob1.cancel() - collectJob2.cancel() } @Test fun deepLinkedNewsResourceIsFetchedAndResetAfterViewing() = runTest { - val collectJob = - launch(UnconfinedTestDispatcher()) { viewModel.deepLinkedNewsResource.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.deepLinkedNewsResource.collect() } newsRepository.sendNewsResources(sampleNewsResources) userDataRepository.setUserData(emptyUserData) @@ -504,7 +475,6 @@ class ForYouViewModelTest { ), ) - collectJob.cancel() } @Test diff --git a/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt b/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt index 987a5bc01f..e1a8ce0dbc 100644 --- a/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt +++ b/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt @@ -80,17 +80,15 @@ class InterestsViewModelTest { @Test fun uiState_whenFollowedTopicsAreLoading_thenShowLoading() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } userDataRepository.setFollowedTopicIds(emptySet()) assertEquals(InterestsUiState.Loading, viewModel.uiState.value) - - collectJob.cancel() } @Test fun uiState_whenFollowingNewTopic_thenShowUpdatedTopics() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } val toggleTopicId = testOutputTopics[1].topic.id topicsRepository.sendTopics(testInputTopics.map { it.topic }) @@ -115,12 +113,11 @@ class InterestsViewModelTest { viewModel.uiState.value, ) - collectJob.cancel() } @Test fun uiState_whenUnfollowingTopics_thenShowUpdatedTopics() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } val toggleTopicId = testOutputTopics[1].topic.id @@ -147,8 +144,6 @@ class InterestsViewModelTest { ), viewModel.uiState.value, ) - - collectJob.cancel() } } diff --git a/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt b/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt index c832401deb..13b0b44960 100644 --- a/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt +++ b/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt @@ -85,20 +85,16 @@ class SearchViewModelTest { fun stateIsEmptyQuery_withEmptySearchQuery() = runTest { searchContentsRepository.addNewsResources(newsResourcesTestData) searchContentsRepository.addTopics(topicsTestData) - val collectJob = - launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() } viewModel.onSearchQueryChanged("") assertEquals(EmptyQuery, viewModel.searchResultUiState.value) - - collectJob.cancel() } @Test fun emptyResultIsReturned_withNotMatchingQuery() = runTest { - val collectJob = - launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() } viewModel.onSearchQueryChanged("XXX") searchContentsRepository.addNewsResources(newsResourcesTestData) @@ -106,32 +102,27 @@ class SearchViewModelTest { val result = viewModel.searchResultUiState.value assertIs(result) - - collectJob.cancel() } @Test fun recentSearches_verifyUiStateIsSuccess() = runTest { - val collectJob = - launch(UnconfinedTestDispatcher()) { viewModel.recentSearchQueriesUiState.collect() } + + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.recentSearchQueriesUiState.collect() } viewModel.onSearchTriggered("kotlin") val result = viewModel.recentSearchQueriesUiState.value assertIs(result) - collectJob.cancel() } @Test fun searchNotReady_withNoFtsTableEntity() = runTest { - val collectJob = - launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.searchResultUiState.collect() } viewModel.onSearchQueryChanged("") assertEquals(SearchNotReady, viewModel.searchResultUiState.value) - collectJob.cancel() } @Test diff --git a/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt b/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt index 9062abee65..1c36650ddb 100644 --- a/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt +++ b/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt @@ -52,8 +52,7 @@ class SettingsViewModelTest { @Test fun stateIsSuccessAfterUserDataLoaded() = runTest { - val collectJob = - launch(UnconfinedTestDispatcher()) { viewModel.settingsUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.settingsUiState.collect() } userDataRepository.setThemeBrand(ANDROID) userDataRepository.setDarkThemeConfig(DARK) @@ -69,6 +68,5 @@ class SettingsViewModelTest { viewModel.settingsUiState.value, ) - collectJob.cancel() } } diff --git a/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index c14e62e313..d6c2b73813 100644 --- a/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -85,7 +85,7 @@ class TopicViewModelTest { @Test fun uiStateTopic_whenSuccess_matchesTopicFromRepository() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } topicsRepository.sendTopics(testInputTopics.map(FollowableTopic::topic)) userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) @@ -98,7 +98,6 @@ class TopicViewModelTest { assertEquals(topicFromRepository, item.followableTopic.topic) - collectJob.cancel() } @Test @@ -113,18 +112,17 @@ class TopicViewModelTest { @Test fun uiStateTopic_whenFollowedIdsSuccessAndTopicLoading_thenShowLoading() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) assertEquals(TopicUiState.Loading, viewModel.topicUiState.value) - collectJob.cancel() } @Test fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccess_thenTopicSuccessAndNewsLoading() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } topicsRepository.sendTopics(testInputTopics.map { it.topic }) userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) @@ -134,13 +132,12 @@ class TopicViewModelTest { assertIs(topicUiState) assertIs(newsUiState) - collectJob.cancel() } @Test fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccessAndNewsIsSuccess_thenAllSuccess() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { + backgroundScope.launch(UnconfinedTestDispatcher()) { combine( viewModel.topicUiState, viewModel.newsUiState, @@ -156,12 +153,11 @@ class TopicViewModelTest { assertIs(topicUiState) assertIs(newsUiState) - collectJob.cancel() } @Test fun uiStateTopic_whenFollowingTopic_thenShowUpdatedTopic() = runTest { - val collectJob = launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } topicsRepository.sendTopics(testInputTopics.map { it.topic }) // Set which topic IDs are followed, not including 0. @@ -174,7 +170,6 @@ class TopicViewModelTest { viewModel.topicUiState.value, ) - collectJob.cancel() } } From 26dd4424f6b507f05936a7ecc5db33ed4d1e830b Mon Sep 17 00:00:00 2001 From: saeedishayan76 Date: Fri, 6 Sep 2024 00:54:22 +0330 Subject: [PATCH 2/4] remove blank lines for resolve spotless error --- .../feature/bookmarks/BookmarksViewModelTest.kt | 2 -- .../nowinandroid/feature/foryou/ForYouViewModelTest.kt | 8 -------- .../apps/nowinandroid/interests/InterestsViewModelTest.kt | 1 - .../nowinandroid/feature/search/SearchViewModelTest.kt | 3 --- .../feature/settings/SettingsViewModelTest.kt | 1 - .../apps/nowinandroid/feature/topic/TopicViewModelTest.kt | 5 ----- 6 files changed, 20 deletions(-) diff --git a/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt b/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt index ff8e6946fb..19ab0ad852 100644 --- a/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt +++ b/feature/bookmarks/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/bookmarks/BookmarksViewModelTest.kt @@ -71,7 +71,6 @@ class BookmarksViewModelTest { val item = viewModel.feedUiState.value assertIs(item) assertEquals(item.feed.size, 1) - } @Test @@ -87,6 +86,5 @@ class BookmarksViewModelTest { val item = viewModel.feedUiState.value assertIs(item) assertEquals(item.feed.size, 0) - } } diff --git a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt index 5db2a76f9e..812544c0cb 100644 --- a/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt +++ b/feature/foryou/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/foryou/ForYouViewModelTest.kt @@ -108,7 +108,6 @@ class ForYouViewModelTest { viewModel.onboardingUiState.value, ) assertEquals(NewsFeedUiState.Loading, viewModel.feedState.value) - } @Test @@ -121,7 +120,6 @@ class ForYouViewModelTest { true, viewModel.isSyncing.value, ) - } @Test @@ -140,7 +138,6 @@ class ForYouViewModelTest { @Test fun onboardingIsShownWhenNewsResourcesAreLoading() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.onboardingUiState.collect() } backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.feedState.collect() } @@ -250,7 +247,6 @@ class ForYouViewModelTest { ), viewModel.feedState.value, ) - } @Test @@ -283,8 +279,6 @@ class ForYouViewModelTest { ), viewModel.feedState.value, ) - - } @Test @@ -434,7 +428,6 @@ class ForYouViewModelTest { ), viewModel.feedState.value, ) - } @Test @@ -474,7 +467,6 @@ class ForYouViewModelTest { ), ), ) - } @Test diff --git a/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt b/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt index e1a8ce0dbc..3cf8d825b3 100644 --- a/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt +++ b/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt @@ -112,7 +112,6 @@ class InterestsViewModelTest { ), viewModel.uiState.value, ) - } @Test diff --git a/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt b/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt index 13b0b44960..a62965b527 100644 --- a/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt +++ b/feature/search/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/search/SearchViewModelTest.kt @@ -106,13 +106,11 @@ class SearchViewModelTest { @Test fun recentSearches_verifyUiStateIsSuccess() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.recentSearchQueriesUiState.collect() } viewModel.onSearchTriggered("kotlin") val result = viewModel.recentSearchQueriesUiState.value assertIs(result) - } @Test @@ -122,7 +120,6 @@ class SearchViewModelTest { viewModel.onSearchQueryChanged("") assertEquals(SearchNotReady, viewModel.searchResultUiState.value) - } @Test diff --git a/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt b/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt index 1c36650ddb..f977612a15 100644 --- a/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt +++ b/feature/settings/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/settings/SettingsViewModelTest.kt @@ -67,6 +67,5 @@ class SettingsViewModelTest { ), viewModel.settingsUiState.value, ) - } } diff --git a/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index d6c2b73813..9d0b8eb719 100644 --- a/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -97,7 +97,6 @@ class TopicViewModelTest { ).first() assertEquals(topicFromRepository, item.followableTopic.topic) - } @Test @@ -116,7 +115,6 @@ class TopicViewModelTest { userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) assertEquals(TopicUiState.Loading, viewModel.topicUiState.value) - } @Test @@ -131,7 +129,6 @@ class TopicViewModelTest { assertIs(topicUiState) assertIs(newsUiState) - } @Test @@ -152,7 +149,6 @@ class TopicViewModelTest { assertIs(topicUiState) assertIs(newsUiState) - } @Test @@ -169,7 +165,6 @@ class TopicViewModelTest { TopicUiState.Success(followableTopic = testOutputTopics[0]), viewModel.topicUiState.value, ) - } } From 6f40606c5488bc559ce01f5a668a315505a85e4f Mon Sep 17 00:00:00 2001 From: saeedishayan76 Date: Sat, 7 Sep 2024 03:07:25 +0330 Subject: [PATCH 3/4] InterstsViewModelTest fix spotless Issue --- .../apps/nowinandroid/interests/InterestsViewModelTest.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt b/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt index 3cf8d825b3..cdf21f3259 100644 --- a/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt +++ b/feature/interests/src/test/kotlin/com/google/samples/apps/nowinandroid/interests/InterestsViewModelTest.kt @@ -80,7 +80,7 @@ class InterestsViewModelTest { @Test fun uiState_whenFollowedTopicsAreLoading_thenShowLoading() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } userDataRepository.setFollowedTopicIds(emptySet()) assertEquals(InterestsUiState.Loading, viewModel.uiState.value) @@ -88,7 +88,7 @@ class InterestsViewModelTest { @Test fun uiState_whenFollowingNewTopic_thenShowUpdatedTopics() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } val toggleTopicId = testOutputTopics[1].topic.id topicsRepository.sendTopics(testInputTopics.map { it.topic }) @@ -116,7 +116,7 @@ class InterestsViewModelTest { @Test fun uiState_whenUnfollowingTopics_thenShowUpdatedTopics() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.uiState.collect() } val toggleTopicId = testOutputTopics[1].topic.id From 987e87f4edf76045ad9036dd7eb0fb3f15e8310e Mon Sep 17 00:00:00 2001 From: saeedishayan76 Date: Sat, 7 Sep 2024 15:18:23 +0330 Subject: [PATCH 4/4] Check topicViewModelTest for spotless --- .../nowinandroid/feature/topic/TopicViewModelTest.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt b/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt index 9d0b8eb719..34f21a59a3 100644 --- a/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt +++ b/feature/topic/src/test/kotlin/com/google/samples/apps/nowinandroid/feature/topic/TopicViewModelTest.kt @@ -85,7 +85,7 @@ class TopicViewModelTest { @Test fun uiStateTopic_whenSuccess_matchesTopicFromRepository() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } topicsRepository.sendTopics(testInputTopics.map(FollowableTopic::topic)) userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) @@ -111,7 +111,7 @@ class TopicViewModelTest { @Test fun uiStateTopic_whenFollowedIdsSuccessAndTopicLoading_thenShowLoading() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) assertEquals(TopicUiState.Loading, viewModel.topicUiState.value) @@ -120,7 +120,7 @@ class TopicViewModelTest { @Test fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccess_thenTopicSuccessAndNewsLoading() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } topicsRepository.sendTopics(testInputTopics.map { it.topic }) userDataRepository.setFollowedTopicIds(setOf(testInputTopics[1].topic.id)) @@ -134,7 +134,7 @@ class TopicViewModelTest { @Test fun uiStateTopic_whenFollowedIdsSuccessAndTopicSuccessAndNewsIsSuccess_thenAllSuccess() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { + backgroundScope.launch(UnconfinedTestDispatcher()) { combine( viewModel.topicUiState, viewModel.newsUiState, @@ -153,7 +153,7 @@ class TopicViewModelTest { @Test fun uiStateTopic_whenFollowingTopic_thenShowUpdatedTopic() = runTest { - backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } + backgroundScope.launch(UnconfinedTestDispatcher()) { viewModel.topicUiState.collect() } topicsRepository.sendTopics(testInputTopics.map { it.topic }) // Set which topic IDs are followed, not including 0.