From 4f3e89148440eb86f34e3da4ea725e6751d09642 Mon Sep 17 00:00:00 2001 From: Gabriel Luong Date: Mon, 7 Mar 2022 11:21:43 -0500 Subject: [PATCH] For #24114 - Refactor ext/HomeFragmentStateTest to ext/AppStateTest --- ...meFragmentStateTest.kt => AppStateTest.kt} | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) rename app/src/test/java/org/mozilla/fenix/ext/{HomeFragmentStateTest.kt => AppStateTest.kt} (91%) diff --git a/app/src/test/java/org/mozilla/fenix/ext/HomeFragmentStateTest.kt b/app/src/test/java/org/mozilla/fenix/ext/AppStateTest.kt similarity index 91% rename from app/src/test/java/org/mozilla/fenix/ext/HomeFragmentStateTest.kt rename to app/src/test/java/org/mozilla/fenix/ext/AppStateTest.kt index 15bea6a68..723ab9e07 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/HomeFragmentStateTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/AppStateTest.kt @@ -11,14 +11,14 @@ import org.junit.Assert.assertNull import org.junit.Assert.assertSame import org.junit.Assert.assertTrue import org.junit.Test -import org.mozilla.fenix.home.HomeFragmentState +import org.mozilla.fenix.components.appstate.AppState import org.mozilla.fenix.home.pocket.POCKET_STORIES_DEFAULT_CATEGORY_NAME import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesCategory import org.mozilla.fenix.home.pocket.PocketRecommendedStoriesSelectedCategory import org.mozilla.fenix.home.recenttabs.RecentTab import kotlin.random.Random -class HomeFragmentStateTest { +class AppStateTest { private val otherStoriesCategory = PocketRecommendedStoriesCategory("other", getFakePocketStories(3, "other")) private val anotherStoriesCategory = @@ -30,55 +30,55 @@ class HomeFragmentStateTest { @Test fun `GIVEN no category is selected WHEN getFilteredStories is called THEN only Pocket stories from the default category are returned`() { - val homeState = HomeFragmentState( + val state = AppState( pocketStoriesCategories = listOf( otherStoriesCategory, anotherStoriesCategory, defaultStoriesCategory ) ) - var result = homeState.getFilteredStories(2) + var result = state.getFilteredStories(2) assertNull(result.firstOrNull { it.category != POCKET_STORIES_DEFAULT_CATEGORY_NAME }) - result = homeState.getFilteredStories(5) + result = state.getFilteredStories(5) assertNull(result.firstOrNull { it.category != POCKET_STORIES_DEFAULT_CATEGORY_NAME }) } @Test fun `GIVEN no category is selected WHEN getFilteredStories is called THEN no more than the indicated number of stories are returned`() { - val homeState = HomeFragmentState( + val state = AppState( pocketStoriesCategories = listOf( otherStoriesCategory, anotherStoriesCategory, defaultStoriesCategory ) ) // Asking for fewer than available - var result = homeState.getFilteredStories(2) + var result = state.getFilteredStories(2) assertEquals(2, result.size) // Asking for more than available - result = homeState.getFilteredStories(5) + result = state.getFilteredStories(5) assertEquals(3, result.size) } @Test fun `GIVEN a category is selected WHEN getFilteredStories is called for fewer than in the category THEN only stories from that category are returned`() { - val homeState = HomeFragmentState( + val state = AppState( pocketStoriesCategories = listOf(otherStoriesCategory, anotherStoriesCategory, defaultStoriesCategory), pocketStoriesCategoriesSelections = listOf(PocketRecommendedStoriesSelectedCategory(otherStoriesCategory.name)) ) - var result = homeState.getFilteredStories(2) + var result = state.getFilteredStories(2) assertEquals(2, result.size) assertNull(result.firstOrNull { it.category != otherStoriesCategory.name }) - result = homeState.getFilteredStories(3) + result = state.getFilteredStories(3) assertEquals(3, result.size) assertNull(result.firstOrNull { it.category != otherStoriesCategory.name }) } @Test fun `GIVEN two categories are selected WHEN getFilteredStories is called for fewer than in both THEN only stories from those categories are returned`() { - val homeState = HomeFragmentState( + val state = AppState( pocketStoriesCategories = listOf(otherStoriesCategory, anotherStoriesCategory, defaultStoriesCategory), pocketStoriesCategoriesSelections = listOf( PocketRecommendedStoriesSelectedCategory(otherStoriesCategory.name), @@ -86,7 +86,7 @@ class HomeFragmentStateTest { ) ) - var result = homeState.getFilteredStories(2) + var result = state.getFilteredStories(2) assertEquals(2, result.size) assertNull( result.firstOrNull { @@ -94,7 +94,7 @@ class HomeFragmentStateTest { } ) - result = homeState.getFilteredStories(6) + result = state.getFilteredStories(6) assertEquals(6, result.size) assertNull( result.firstOrNull { @@ -105,7 +105,7 @@ class HomeFragmentStateTest { @Test fun `GIVEN two categories are selected WHEN getFilteredStories is called for an odd number of stories THEN there are more by one stories from the newest category`() { - val homeState = HomeFragmentState( + val state = AppState( pocketStoriesCategories = listOf(otherStoriesCategory, anotherStoriesCategory, defaultStoriesCategory), pocketStoriesCategoriesSelections = listOf( PocketRecommendedStoriesSelectedCategory(otherStoriesCategory.name, selectionTimestamp = 0), @@ -113,7 +113,7 @@ class HomeFragmentStateTest { ) ) - val result = homeState.getFilteredStories(5) + val result = state.getFilteredStories(5) assertEquals(5, result.size) assertEquals(2, result.filter { it.category == otherStoriesCategory.name }.size) @@ -242,7 +242,7 @@ class HomeFragmentStateTest { ) } - val homeState = HomeFragmentState( + val state = AppState( pocketStoriesCategories = listOf(firstCategory, secondCategory), pocketStoriesCategoriesSelections = listOf( PocketRecommendedStoriesSelectedCategory(firstCategory.name, selectionTimestamp = 0), @@ -250,7 +250,7 @@ class HomeFragmentStateTest { ) ) - val result = homeState.getFilteredStories(6) + val result = state.getFilteredStories(6) assertEquals(6, result.size) assertSame(secondCategory.stories[2], result.first()) @@ -263,7 +263,7 @@ class HomeFragmentStateTest { @Test fun `GIVEN old selections of categories which do not exist anymore WHEN getFilteredStories is called THEN ignore not found selections`() { - val homeState = HomeFragmentState( + val state = AppState( pocketStoriesCategories = listOf(otherStoriesCategory, anotherStoriesCategory, defaultStoriesCategory), pocketStoriesCategoriesSelections = listOf( PocketRecommendedStoriesSelectedCategory("unexistent"), @@ -271,7 +271,7 @@ class HomeFragmentStateTest { ) ) - val result = homeState.getFilteredStories(6) + val result = state.getFilteredStories(6) assertEquals(3, result.size) assertNull(result.firstOrNull { it.category != anotherStoriesCategory.name }) @@ -281,7 +281,7 @@ class HomeFragmentStateTest { fun `GIVEN recentTabs contains a SearchGroup WHEN recentSearchGroup is called THEN return the group`() { val searchGroup: RecentTab.SearchGroup = mockk() val normalTab: RecentTab.Tab = mockk() - val state = HomeFragmentState(recentTabs = listOf(normalTab, searchGroup)) + val state = AppState(recentTabs = listOf(normalTab, searchGroup)) assertEquals(searchGroup, state.recentSearchGroup) } @@ -290,7 +290,7 @@ class HomeFragmentStateTest { fun `GIVEN recentTabs does not contains SearchGroup WHEN recentSearchGroup is called THEN return null`() { val normalTab1: RecentTab.Tab = mockk() val normalTab2: RecentTab.Tab = mockk() - val state = HomeFragmentState(recentTabs = listOf(normalTab1, normalTab2)) + val state = AppState(recentTabs = listOf(normalTab1, normalTab2)) assertNull(state.recentSearchGroup) }