tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit d914cf1a8532d6295c262afc790e7b35570964a8
parent 2a9e3a93714da283bd348a78f52068e77d36c78e
Author: mcarare <48995920+mcarare@users.noreply.github.com>
Date:   Thu, 27 Nov 2025 14:31:30 +0000

Bug 2002762 - Refactor BookmarksFeatureTest to use StandardTestDispatcher r=android-reviewers,giorga

This patch replaces the usage of `MainCoroutineRule` and `runTestOnMain` with `StandardTestDispatcher` and `runTest`.

Differential Revision: https://phabricator.services.mozilla.com/D274276

Diffstat:
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/bookmarks/BookmarksFeature.kt | 2+-
Mmobile/android/fenix/app/src/test/java/org/mozilla/fenix/home/bookmarks/BookmarksFeatureTest.kt | 22+++++++---------------
2 files changed, 8 insertions(+), 16 deletions(-)

diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/bookmarks/BookmarksFeature.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/home/bookmarks/BookmarksFeature.kt @@ -17,7 +17,7 @@ import org.mozilla.fenix.components.bookmarks.BookmarksUseCase import org.mozilla.fenix.home.HomeFragment /** - * View-bound feature that retrieves a list of [BookmarkNode]s and dispatches + * Lifecycle-aware feature that retrieves a list of [BookmarkNode]s and dispatches * updates to the [AppStore]. * * @param appStore the [AppStore] that holds the state of the [HomeFragment]. diff --git a/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/home/bookmarks/BookmarksFeatureTest.kt b/mobile/android/fenix/app/src/test/java/org/mozilla/fenix/home/bookmarks/BookmarksFeatureTest.kt @@ -7,15 +7,11 @@ package org.mozilla.fenix.home.bookmarks import io.mockk.coEvery import io.mockk.coVerify import io.mockk.mockk -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.advanceUntilIdle -import mozilla.components.concept.storage.BookmarkNode +import kotlinx.coroutines.test.StandardTestDispatcher +import kotlinx.coroutines.test.runTest import mozilla.components.support.test.middleware.CaptureActionsMiddleware -import mozilla.components.support.test.rule.MainCoroutineRule -import mozilla.components.support.test.rule.runTestOnMain import org.junit.Assert.assertEquals import org.junit.Before -import org.junit.Rule import org.junit.Test import org.mozilla.fenix.components.AppStore import org.mozilla.fenix.components.appstate.AppAction @@ -33,32 +29,28 @@ class BookmarksFeatureTest { previewImageUrl = null, ) - @get:Rule - val coroutinesTestRule = MainCoroutineRule() - private val testDispatcher = coroutinesTestRule.testDispatcher - private val scope = coroutinesTestRule.scope + private val testDispatcher = StandardTestDispatcher() @Before fun setup() { coEvery { bookmarksUseCases.retrieveRecentBookmarks() }.coAnswers { listOf(bookmark) } } - @OptIn(ExperimentalCoroutinesApi::class) // advanceUntilIdle @Test fun `GIVEN no bookmarks WHEN feature starts THEN fetch bookmarks and notify store`() = - runTestOnMain { + runTest(testDispatcher) { val feature = BookmarksFeature( appStore, bookmarksUseCases, - scope, + this, testDispatcher, ) - assertEquals(emptyList<BookmarkNode>(), appStore.state.bookmarks) + assertEquals(emptyList<Bookmark>(), appStore.state.bookmarks) feature.start() - advanceUntilIdle() + testScheduler.advanceUntilIdle() coVerify { bookmarksUseCases.retrieveRecentBookmarks()