Browse Source

For #8470 - Fix Unit Tests MockKExceptions (#8471)

master
Emily Kager 2 years ago
committed by GitHub
parent
commit
39db8c9557
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/geckoNightly/java/org/mozilla/fenix/engine/GeckoProvider.kt
  2. 15
      app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt
  3. 11
      app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt

1
app/src/geckoNightly/java/org/mozilla/fenix/engine/GeckoProvider.kt

@ -47,7 +47,6 @@ object GeckoProvider {
val runtimeSettings = builder
.crashHandler(CrashHandlerService::class.java)
.useContentProcessHint(true)
.telemetryDelegate(GeckoAdapter())
.debugLogging(Config.channel.isDebug)
.aboutConfigEnabled(true)

15
app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt

@ -5,10 +5,10 @@
package org.mozilla.fenix.home
import android.view.View
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.navigation.NavController
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
@ -17,21 +17,24 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.engine.Engine
import mozilla.components.feature.tab.collections.TabCollection
import org.junit.After
import mozilla.components.feature.tab.collections.Tab as ComponentTab
import org.junit.Before
import org.junit.Test
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.components.TabCollectionStorage
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.components.metrics.MetricController
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.home.sessioncontrol.DefaultSessionControlController
import org.mozilla.fenix.settings.SupportUtils
import mozilla.components.feature.tab.collections.Tab as ComponentTab
@ExperimentalCoroutinesApi
@UseExperimental(ObsoleteCoroutinesApi::class)
@ -41,7 +44,6 @@ class DefaultSessionControlControllerTest {
private val activity: HomeActivity = mockk(relaxed = true)
private val store: HomeFragmentStore = mockk(relaxed = true)
private val navController: NavController = mockk(relaxed = true)
private val homeLayout: MotionLayout = mockk(relaxed = true)
private val browsingModeManager: BrowsingModeManager = mockk(relaxed = true)
private val closeTab: (sessionId: String) -> Unit = mockk(relaxed = true)
private val closeAllTabs: (isPrivateMode: Boolean) -> Unit = mockk(relaxed = true)
@ -55,12 +57,19 @@ class DefaultSessionControlControllerTest {
mockk(relaxed = true)
private val metrics: MetricController = mockk(relaxed = true)
private val state: HomeFragmentState = mockk(relaxed = true)
private val sessionManager: SessionManager = mockk(relaxed = true)
private val engine: Engine = mockk(relaxed = true)
private val tabCollectionStorage: TabCollectionStorage = mockk(relaxed = true)
private lateinit var controller: DefaultSessionControlController
@Before
fun setup() {
Dispatchers.setMain(mainThreadSurrogate)
mockkStatic("org.mozilla.fenix.ext.ContextKt")
every { activity.components.core.engine } returns engine
every { activity.components.core.sessionManager } returns sessionManager
every { activity.components.core.tabCollectionStorage } returns tabCollectionStorage
every { store.state } returns state
every { state.collections } returns emptyList()

11
app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkControllerTest.kt

@ -29,6 +29,7 @@ import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.DefaultBrowsingModeManager
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.Services
import org.mozilla.fenix.components.metrics.Event
@ -47,6 +48,7 @@ class BookmarkControllerTest {
private val homeActivity: HomeActivity = mockk(relaxed = true)
private val services: Services = mockk(relaxed = true)
private val browsingModeManager: DefaultBrowsingModeManager = mockk(relaxed = true)
private val item =
BookmarkNode(BookmarkNodeType.ITEM, "456", "123", 0, "Mozilla", "http://mozilla.org", null)
@ -79,9 +81,12 @@ class BookmarkControllerTest {
// needed for mocking 'getSystemService<ClipboardManager>()'
mockkStatic(
"androidx.core.content.ContextCompat",
"android.content.ClipData"
"android.content.ClipData",
"org.mozilla.fenix.ext.ContextKt"
)
every { homeActivity.components.browsingModeManager } returns browsingModeManager
every { homeActivity.components.services } returns services
every { navController.currentDestination } returns NavDestination("").apply {
id = R.id.bookmarkFragment
@ -204,7 +209,7 @@ class BookmarkControllerTest {
verifyOrder {
invokePendingDeletion.invoke()
homeActivity.components.browsingModeManager.mode = BrowsingMode.Normal
browsingModeManager.mode = BrowsingMode.Normal
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
}
}
@ -215,7 +220,7 @@ class BookmarkControllerTest {
verifyOrder {
invokePendingDeletion.invoke()
homeActivity.components.browsingModeManager.mode = BrowsingMode.Private
browsingModeManager.mode = BrowsingMode.Private
homeActivity.openToBrowserAndLoad(item.url!!, true, BrowserDirection.FromBookmarks)
}
}

Loading…
Cancel
Save