2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-02 03:40:16 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/20524 - Remove redundant coroutine dispatchers from tests

This commit is contained in:
Alexandru2909 2022-01-04 17:33:54 +02:00 committed by mergify[bot]
parent 68be05d051
commit e683694d05
35 changed files with 57 additions and 178 deletions

View File

@ -14,7 +14,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.RestoreCompleteAction
import mozilla.components.browser.state.action.TabListAction
@ -27,7 +26,6 @@ import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Rule
@ -44,7 +42,6 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
import org.mozilla.fenix.onboarding.FenixOnboarding
import org.mozilla.fenix.utils.Settings
import java.lang.Exception
@RunWith(FenixRobolectricTestRunner::class)
class BrowserFragmentTest {
@ -60,10 +57,8 @@ class BrowserFragmentTest {
private lateinit var navController: NavController
private lateinit var onboarding: FenixOnboarding
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setup() {
@ -95,11 +90,6 @@ class BrowserFragmentTest {
every { context.components.core.store } returns store
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun `GIVEN fragment is added WHEN selected tab changes THEN theme is updated`() {
browserFragment.observeTabSelection(store)

View File

@ -15,7 +15,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
@ -48,10 +47,8 @@ class OpenInAppOnboardingObserverTest {
private lateinit var container: ViewGroup
private lateinit var infoBanner: DynamicInfoBanner
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setUp() {

View File

@ -7,7 +7,6 @@ package org.mozilla.fenix.components.toolbar
import io.mockk.clearMocks
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.TabSessionState
@ -27,10 +26,8 @@ class MenuPresenterTest {
private lateinit var menuPresenter: MenuPresenter
private lateinit var menuToolbar: BrowserToolbar
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setup() {

View File

@ -15,7 +15,6 @@ import io.mockk.spyk
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import mozilla.components.browser.state.action.SearchAction
import mozilla.components.browser.state.action.TabListAction
@ -65,10 +64,8 @@ import mozilla.components.feature.tab.collections.Tab as ComponentTab
@OptIn(ExperimentalCoroutinesApi::class)
class DefaultSessionControlControllerTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val activity: HomeActivity = mockk(relaxed = true)
private val fragmentStore: HomeFragmentStore = mockk(relaxed = true)
@ -144,7 +141,6 @@ class DefaultSessionControlControllerTest {
@After
fun cleanUp() {
scope.cleanupTestCoroutines()
testDispatcher.cleanupTestCoroutines()
}
@Test

View File

@ -7,7 +7,6 @@ package org.mozilla.fenix.home
import android.graphics.Bitmap
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction.UpdateIconAction
import mozilla.components.browser.state.action.ContentAction.UpdateTitleAction
import mozilla.components.browser.state.action.MediaSessionAction
@ -46,7 +45,7 @@ class RecentTabsListFeatureTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setup() {

View File

@ -12,13 +12,11 @@ import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import mozilla.appservices.places.BookmarkRoot
import mozilla.components.concept.engine.EngineSession
import mozilla.components.concept.engine.EngineSession.LoadUrlFlags.Companion.ALLOW_JAVASCRIPT_URL
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -34,10 +32,8 @@ import org.mozilla.fenix.home.recentbookmarks.controller.DefaultRecentBookmarksC
@OptIn(ExperimentalCoroutinesApi::class)
class DefaultRecentBookmarksControllerTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val activity: HomeActivity = mockk(relaxed = true)
private val navController: NavController = mockk(relaxUnitFun = true)
@ -63,11 +59,6 @@ class DefaultRecentBookmarksControllerTest {
)
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun `WHEN a recently saved bookmark is clicked THEN the selected bookmark is opened`() {
every { navController.currentDestination } returns mockk {

View File

@ -9,13 +9,11 @@ import io.mockk.coVerify
import io.mockk.mockk
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.middleware.CaptureActionsMiddleware
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
@ -31,7 +29,6 @@ class RecentBookmarksFeatureTest {
private val middleware = CaptureActionsMiddleware<HomeFragmentState, HomeFragmentAction>()
private val homeStore = HomeFragmentStore(middlewares = listOf(middleware))
private val bookmarksUseCases: BookmarksUseCase = mockk(relaxed = true)
private val testDispatcher = TestCoroutineDispatcher()
private val bookmark = RecentBookmark(
title = null,
url = "https://www.example.com",
@ -39,18 +36,14 @@ class RecentBookmarksFeatureTest {
)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
@Before
fun setup() {
coEvery { bookmarksUseCases.retrieveRecentBookmarks() }.coAnswers { listOf(bookmark) }
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun `GIVEN no recent bookmarks WHEN feature starts THEN fetch bookmarks and notify store`() =
testDispatcher.runBlockingTest {

View File

@ -11,7 +11,6 @@ import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
@ -29,10 +28,8 @@ import org.mozilla.fenix.components.metrics.MetricController
@OptIn(ExperimentalCoroutinesApi::class)
class RecentTabControllerTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val navController: NavController = mockk(relaxed = true)
private val selectTabUseCase: TabsUseCases = mockk(relaxed = true)

View File

@ -8,7 +8,6 @@ import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.slot
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.state.createTab
import mozilla.components.concept.storage.DocumentType
import mozilla.components.concept.storage.HistoryMetadataKey
@ -27,10 +26,9 @@ class HistoryMetadataServiceTest {
private lateinit var service: HistoryMetadataService
private lateinit var storage: HistoryMetadataStorage
val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
val testDispatcher = coroutinesTestRule.testDispatcher
@Before
fun setup() {

View File

@ -12,7 +12,6 @@ import io.mockk.slot
import io.mockk.spyk
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
import mozilla.components.concept.storage.DocumentType
@ -46,10 +45,10 @@ class RecentVisitsFeatureTest {
private val middleware = CaptureActionsMiddleware<HomeFragmentState, HomeFragmentAction>()
private val homeStore = HomeFragmentStore(middlewares = listOf(middleware))
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
@Before
fun setup() {

View File

@ -14,7 +14,6 @@ import io.mockk.verify
import io.mockk.verifyOrder
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import mozilla.components.browser.state.action.HistoryMetadataAction
import mozilla.components.browser.state.store.BrowserStore
@ -41,10 +40,9 @@ import org.mozilla.fenix.home.recentvisits.RecentlyVisitedItem.RecentHistoryHigh
@OptIn(ExperimentalCoroutinesApi::class)
class RecentVisitsControllerTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
private val selectOrAddTabUseCase: SelectOrAddUseCase = mockk(relaxed = true)
private val navController = mockk<NavController>(relaxed = true)

View File

@ -9,7 +9,6 @@ import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.browser.storage.sync.PlacesHistoryStorage
@ -38,11 +37,10 @@ import org.mozilla.fenix.library.historymetadata.HistoryMetadataGroupFragmentSto
@RunWith(FenixRobolectricTestRunner::class)
class HistoryMetadataGroupControllerTest {
private val testDispatcher = TestCoroutineDispatcher()
private val scope = TestCoroutineScope()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
private val scope = TestCoroutineScope(testDispatcher)
private val activity: HomeActivity = mockk(relaxed = true)
private val store: HistoryMetadataGroupFragmentStore = mockk(relaxed = true)

View File

@ -8,7 +8,6 @@ import android.content.ComponentName
import android.content.Intent
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
@ -16,7 +15,6 @@ import mozilla.components.feature.privatemode.notification.AbstractPrivateNotifi
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
@ -38,10 +36,8 @@ class PrivateNotificationServiceTest {
private lateinit var controller: ServiceController<PrivateNotificationService>
private lateinit var store: BrowserStore
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setup() {
@ -56,11 +52,6 @@ class PrivateNotificationServiceTest {
)
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun `service opens home activity in private mode if app is in private mode`() {
val selectedPrivateTab = createTab("https://mozilla.org", private = true)

View File

@ -9,11 +9,9 @@ import androidx.preference.Preference
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.concept.fetch.Client
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertTrue
@ -34,10 +32,9 @@ import java.io.IOException
@RunWith(FenixRobolectricTestRunner::class)
class SettingsFragmentTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
@Before
fun setup() {
@ -54,11 +51,6 @@ class SettingsFragmentTest {
every { Config.channel } returns ReleaseChannel.Nightly
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun `Add-on collection override pref is visible if debug menu active`() {
val settingsFragment = SettingsFragment()

View File

@ -9,7 +9,6 @@ import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.concept.storage.CreditCardNumber
@ -32,13 +31,12 @@ class DefaultCreditCardEditorControllerTest {
private val navController: NavController = mockk(relaxed = true)
private val metrics: MetricController = mockk(relaxed = true)
private val testCoroutineScope = TestCoroutineScope()
private val testDispatcher = TestCoroutineDispatcher()
private lateinit var controller: DefaultCreditCardEditorController
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
private val testCoroutineScope = TestCoroutineScope(testDispatcher)
@Before
fun setup() {
@ -56,7 +54,6 @@ class DefaultCreditCardEditorControllerTest {
@After
fun cleanUp() {
testCoroutineScope.cleanupTestCoroutines()
testDispatcher.cleanupTestCoroutines()
}
@Test

View File

@ -11,7 +11,6 @@ import io.mockk.verify
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.GlobalScope.coroutineContext
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.browser.icons.BrowserIcons
import mozilla.components.browser.state.action.EngineAction
@ -22,7 +21,6 @@ import mozilla.components.concept.storage.HistoryStorage
import mozilla.components.feature.downloads.DownloadsUseCases
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -31,10 +29,8 @@ import org.mozilla.fenix.components.PermissionStorage
@OptIn(ExperimentalCoroutinesApi::class)
class DefaultDeleteBrowsingDataControllerTest {
val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private var removeAllTabs: TabsUseCases.RemoveAllTabsUseCase = mockk(relaxed = true)
private var removeAllDownloads: DownloadsUseCases.RemoveAllDownloadsUseCase = mockk(relaxed = true)
@ -60,11 +56,6 @@ class DefaultDeleteBrowsingDataControllerTest {
)
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun deleteTabs() = runBlockingTest {

View File

@ -10,7 +10,6 @@ import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.concept.storage.EncryptedLogin
@ -32,16 +31,15 @@ import org.mozilla.fenix.settings.logins.fragment.EditLoginFragmentDirections
@RunWith(FenixRobolectricTestRunner::class)
class SavedLoginsStorageControllerTest {
val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val ioDispatcher = coroutinesTestRule.testDispatcher
private val scope = TestCoroutineScope(ioDispatcher)
private val passwordsStorage: SyncableLoginsStorage = mockk(relaxed = true)
private lateinit var controller: SavedLoginsStorageController
private val navController: NavController = mockk(relaxed = true)
private val loginsFragmentStore: LoginsFragmentStore = mockk(relaxed = true)
private val scope = TestCoroutineScope()
private val ioDispatcher = TestCoroutineDispatcher()
private val loginMock: Login = mockk(relaxed = true)
@Before
@ -64,8 +62,6 @@ class SavedLoginsStorageControllerTest {
@After
fun cleanUp() {
scope.cleanupTestCoroutines()
ioDispatcher.cleanupTestCoroutines()
testDispatcher.cleanupTestCoroutines()
}
@Test

View File

@ -13,7 +13,6 @@ import io.mockk.slot
import io.mockk.spyk
import io.mockk.verify
import junit.framework.TestCase.assertNotSame
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.action.TrackingProtectionAction.TrackerBlockedAction
import mozilla.components.browser.state.action.TrackingProtectionAction.TrackerLoadedAction
@ -25,7 +24,6 @@ import mozilla.components.concept.engine.content.blocking.TrackerLog
import mozilla.components.feature.session.TrackingProtectionUseCases
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -35,10 +33,9 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class QuickSettingsSheetDialogFragmentTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private lateinit var lifecycleOwner: MockedLifecycleOwner
private lateinit var fragment: QuickSettingsSheetDialogFragment
private lateinit var store: BrowserStore
@ -54,11 +51,6 @@ class QuickSettingsSheetDialogFragmentTest {
every { fragment.activity } returns mockk(relaxed = true)
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun `WHEN a tracker is loaded THEN trackers view is updated`() {
val tab = createTab("mozilla.org")

View File

@ -15,7 +15,6 @@ import io.mockk.mockk
import io.mockk.runs
import io.mockk.spyk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import mozilla.components.service.nimbus.NimbusApi
import mozilla.components.support.test.mock
@ -46,12 +45,11 @@ class StudiesViewTest {
@RelaxedMockK
private lateinit var settings: Settings
private val testCoroutineScope = TestCoroutineScope()
private val testDispatcher = TestCoroutineDispatcher()
private lateinit var view: StudiesView
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testCoroutineScope = TestCoroutineScope(coroutinesTestRule.testDispatcher)
@Before
fun setup() {
@ -73,7 +71,6 @@ class StudiesViewTest {
@After
fun cleanUp() {
testCoroutineScope.cleanupTestCoroutines()
testDispatcher.cleanupTestCoroutines()
}
@Test

View File

@ -19,7 +19,6 @@ import io.mockk.spyk
import io.mockk.verify
import io.mockk.verifyOrder
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.TestCoroutineScope
import mozilla.components.concept.engine.prompt.ShareData
import mozilla.components.concept.sync.Device
@ -63,21 +62,21 @@ class ShareControllerTest {
TabData("title1", "url1")
)
private val textToShare = "${shareData[0].url}\n\n${shareData[1].url}"
private val testDispatcher = TestCoroutineDispatcher()
private val testCoroutineScope = TestCoroutineScope()
private val sendTabUseCases = mockk<SendTabUseCases>(relaxed = true)
private val snackbar = mockk<FenixSnackbar>(relaxed = true)
private val navController = mockk<NavController>(relaxed = true)
private val dismiss = mockk<(ShareController.Result) -> Unit>(relaxed = true)
private val recentAppStorage = mockk<RecentAppsStorage>(relaxed = true)
@get:Rule
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
private val testCoroutineScope = TestCoroutineScope(testDispatcher)
private val controller = DefaultShareController(
context, shareSubject, shareData, sendTabUseCases, snackbar, navController,
recentAppStorage, testCoroutineScope, testDispatcher, dismiss
)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
@Before
fun setUp() {
every { context.metrics } returns metrics

View File

@ -11,7 +11,6 @@ import androidx.navigation.NavController
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
@ -37,10 +36,8 @@ class PwaOnboardingObserverTest {
private lateinit var settings: Settings
private lateinit var webAppUseCases: WebAppUseCases
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setUp() {

View File

@ -8,7 +8,6 @@ import io.mockk.Called
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
@ -22,7 +21,7 @@ class CloseOnLastTabBindingTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
@Test
fun `WHEN the binding starts THEN do nothing`() {

View File

@ -12,7 +12,6 @@ import io.mockk.mockkStatic
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
@ -26,7 +25,7 @@ class FloatingActionButtonBindingTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
private val actionButton: ExtendedFloatingActionButton = mockk(relaxed = true)
private val browserTrayInteractor: BrowserTrayInteractor = mockk(relaxed = true)

View File

@ -7,7 +7,6 @@ package org.mozilla.fenix.tabstray
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.middleware.CaptureActionsMiddleware
import mozilla.components.support.test.rule.MainCoroutineRule
@ -19,7 +18,7 @@ class MenuIntegrationTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
private val captureMiddleware = CaptureActionsMiddleware<TabsTrayState, TabsTrayAction>()
private val tabsTrayStore = TabsTrayStore(middlewares = listOf(captureMiddleware))

View File

@ -7,15 +7,14 @@ package org.mozilla.fenix.tabstray
import android.content.Context
import androidx.navigation.NavController
import androidx.navigation.NavDirections
import io.mockk.coVerify
import io.mockk.every
import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkStatic
import io.mockk.coVerify
import io.mockk.verify
import io.mockk.verifyOrder
import kotlinx.coroutines.test.TestCoroutineDispatcher
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
@ -53,10 +52,9 @@ class NavigationInteractorTest {
private val accountManager: FxaAccountManager = mockk(relaxed = true)
private val activity: HomeActivity = mockk(relaxed = true)
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private val testDispatcher = coroutinesTestRule.testDispatcher
@Before
fun setup() {

View File

@ -15,7 +15,6 @@ import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.Before
@ -29,7 +28,7 @@ class SecureTabsTrayBindingTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
private val settings: Settings = mockk(relaxed = true)
private val fragment: Fragment = mockk(relaxed = true)

View File

@ -7,7 +7,6 @@ package org.mozilla.fenix.tabstray
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
@ -21,7 +20,7 @@ class TabCounterBindingTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
@Test
fun `WHEN normalTabs changes THEN update counter`() {

View File

@ -11,7 +11,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
@ -36,7 +35,7 @@ class TabsTrayInfoBannerBindingTest {
private lateinit var settings: Settings
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setUp() {

View File

@ -8,7 +8,6 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.tabstray.TabsAdapter.Companion.PAYLOAD_DONT_HIGHLIGHT_SELECTED_ITEM
import mozilla.components.browser.tabstray.TabsAdapter.Companion.PAYLOAD_HIGHLIGHT_SELECTED_ITEM
import mozilla.components.support.test.libstate.ext.waitUntilIdle
@ -23,7 +22,7 @@ class SelectedItemAdapterBindingTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
private val adapter = mockk<BrowserTabsAdapter>(relaxed = true)

View File

@ -6,7 +6,6 @@ package org.mozilla.fenix.tabstray.browser
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.Assert.assertFalse
@ -21,7 +20,7 @@ class SwipeToDeleteBindingTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
@Test
fun `WHEN started THEN update the swipeable state`() {

View File

@ -5,7 +5,6 @@
package org.mozilla.fenix.tabstray.syncedtabs
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.support.test.libstate.ext.waitUntilIdle
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.Assert.assertFalse
@ -18,7 +17,7 @@ import org.mozilla.fenix.tabstray.TabsTrayStore
class SyncButtonBindingTest {
@OptIn(ExperimentalCoroutinesApi::class)
@get:Rule
val coroutinesTestRule = MainCoroutineRule(TestCoroutineDispatcher())
val coroutinesTestRule = MainCoroutineRule()
@Test
fun `WHEN syncing state is true THEN invoke callback`() {

View File

@ -7,7 +7,6 @@ package org.mozilla.fenix.telemetry
import androidx.test.core.app.ApplicationProvider
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.TabListAction
@ -43,10 +42,9 @@ class TelemetryMiddlewareTest {
private lateinit var settings: Settings
private lateinit var telemetryMiddleware: TelemetryMiddleware
private lateinit var metrics: MetricController
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@get:Rule
val gleanRule = GleanTestRule(ApplicationProvider.getApplicationContext())

View File

@ -12,7 +12,6 @@ import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.spyk
import io.mockk.unmockkStatic
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
@ -38,10 +37,8 @@ class DefaultToolbarMenuTest {
private lateinit var bookmarksStorage: BookmarksStorage
private lateinit var pinnedSiteStorage: PinnedSiteStorage
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@Before
fun setUp() {

View File

@ -12,7 +12,6 @@ import io.mockk.mockk
import io.mockk.spyk
import io.mockk.verify
import junit.framework.TestCase.assertNotSame
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.action.TrackingProtectionAction.TrackerBlockedAction
@ -23,7 +22,6 @@ import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.test.ext.joinBlocking
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -33,10 +31,8 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class TrackingProtectionPanelDialogFragmentTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
private lateinit var lifecycleOwner: MockedLifecycleOwner
private lateinit var fragment: TrackingProtectionPanelDialogFragment
private lateinit var store: BrowserStore
@ -52,11 +48,6 @@ class TrackingProtectionPanelDialogFragmentTest {
every { fragment.activity } returns mockk(relaxed = true)
}
@After
fun cleanUp() {
testDispatcher.cleanupTestCoroutines()
}
@Test
fun `WHEN the url is updated THEN the url view is updated`() {
val trackingProtectionStore: TrackingProtectionStore = mockk(relaxed = true)
@ -132,6 +123,7 @@ class TrackingProtectionPanelDialogFragmentTest {
fragment.updateTrackers(tab)
}
}
private fun addAndSelectTab(tab: TabSessionState) {
store.dispatch(TabListAction.AddTabAction(tab)).joinBlocking()
store.dispatch(TabListAction.SelectTabAction(tab.id)).joinBlocking()

View File

@ -4,7 +4,6 @@
package org.mozilla.fenix.utils
import kotlinx.coroutines.test.TestCoroutineDispatcher
import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.ReaderState
@ -21,10 +20,9 @@ import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class ToolbarPopupWindowTest {
private val testDispatcher = TestCoroutineDispatcher()
@get:Rule
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
val coroutinesTestRule = MainCoroutineRule()
@Test
fun `getUrlForClipboard should get the right URL`() {