diff --git a/app/src/test/java/org/mozilla/fenix/addons/AddonDetailsViewTest.kt b/app/src/test/java/org/mozilla/fenix/addons/AddonDetailsViewTest.kt index 288c5d2f5..252b26f45 100644 --- a/app/src/test/java/org/mozilla/fenix/addons/AddonDetailsViewTest.kt +++ b/app/src/test/java/org/mozilla/fenix/addons/AddonDetailsViewTest.kt @@ -81,25 +81,28 @@ class AddonDetailsViewTest { @Test fun `bind addons version`() { - detailsView.bind(baseAddon.copy( + val addon1 = baseAddon.copy( version = "1.0.0", installedState = null - )) + ) + + detailsView.bind(addon1) assertEquals("1.0.0", view.version_text.text) view.version_text.performLongClick() - verify(exactly = 0) { interactor.showUpdaterDialog(any()) } + verify(exactly = 0) { interactor.showUpdaterDialog(addon1) } - detailsView.bind(baseAddon.copy( + val addon2 = baseAddon.copy( version = "1.0.0", installedState = Addon.InstalledState( id = "", version = "2.0.0", optionsPageUrl = null ) - )) + ) + detailsView.bind(addon2) assertEquals("2.0.0", view.version_text.text) view.version_text.performLongClick() - verify { interactor.showUpdaterDialog(any()) } + verify { interactor.showUpdaterDialog(addon2) } } @Test diff --git a/app/src/test/java/org/mozilla/fenix/browser/browsingmode/DefaultBrowsingModeManagerTest.kt b/app/src/test/java/org/mozilla/fenix/browser/browsingmode/DefaultBrowsingModeManagerTest.kt index 1130996d6..8313debc7 100644 --- a/app/src/test/java/org/mozilla/fenix/browser/browsingmode/DefaultBrowsingModeManagerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/browser/browsingmode/DefaultBrowsingModeManagerTest.kt @@ -32,12 +32,12 @@ class DefaultBrowsingModeManagerTest { manager.mode = BrowsingMode.Private manager.mode = BrowsingMode.Private - verify(exactly = 3) { callback.invoke(any()) } + verify(exactly = 3) { callback.invoke(BrowsingMode.Private) } manager.mode = BrowsingMode.Normal manager.mode = BrowsingMode.Normal - verify(exactly = 5) { callback.invoke(any()) } + verify(exactly = 2) { callback.invoke(BrowsingMode.Normal) } } @Test diff --git a/app/src/test/java/org/mozilla/fenix/components/metrics/BreadcrumbRecorderTest.kt b/app/src/test/java/org/mozilla/fenix/components/metrics/BreadcrumbRecorderTest.kt index ea9add329..61a62981b 100644 --- a/app/src/test/java/org/mozilla/fenix/components/metrics/BreadcrumbRecorderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/metrics/BreadcrumbRecorderTest.kt @@ -13,6 +13,7 @@ import mozilla.components.lib.crash.Crash import mozilla.components.lib.crash.CrashReporter import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.support.base.crash.Breadcrumb +import org.junit.Assert.assertEquals import org.junit.Test internal class BreadcrumbRecorderTest { @@ -36,17 +37,18 @@ internal class BreadcrumbRecorderTest { ) ) - fun getBreadcrumbMessage(@Suppress("UNUSED_PARAMETER") destination: NavDestination): String { - return "test" - } - val navController: NavController = mockk() val navDestination: NavDestination = mockk() - val breadCrumbRecorder = - BreadcrumbsRecorder(reporter, navController, ::getBreadcrumbMessage) + val breadCrumbRecorder = BreadcrumbsRecorder(reporter, navController) { "test" } breadCrumbRecorder.onDestinationChanged(navController, navDestination, null) - verify { reporter.recordCrashBreadcrumb(any()) } + verify { + reporter.recordCrashBreadcrumb(withArg { + assertEquals("test", it.message) + assertEquals("DestinationChanged", it.category) + assertEquals(Breadcrumb.Level.INFO, it.level) + }) + } } } diff --git a/app/src/test/java/org/mozilla/fenix/components/tips/providers/MigrationTipProviderTest.kt b/app/src/test/java/org/mozilla/fenix/components/tips/providers/MigrationTipProviderTest.kt index a01272b38..cc45ed743 100644 --- a/app/src/test/java/org/mozilla/fenix/components/tips/providers/MigrationTipProviderTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/tips/providers/MigrationTipProviderTest.kt @@ -8,7 +8,6 @@ import android.content.Context import android.content.Intent import android.content.Intent.ACTION_VIEW import androidx.core.net.toUri -import io.mockk.MockKMatcherScope import io.mockk.Runs import io.mockk.every import io.mockk.just @@ -32,6 +31,7 @@ import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.MozillaProductDetector import org.mozilla.fenix.components.metrics.MozillaProductDetector.MozillaProducts import org.mozilla.fenix.components.tips.TipType +import org.mozilla.fenix.ext.intentFilterEq import org.mozilla.fenix.ext.settings import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.settings.SupportUtils @@ -205,7 +205,4 @@ class MigrationTipProviderTest { every { settings.shouldDisplayFenixMovingTip() } returns true assertTrue(MigrationTipProvider(context).shouldDisplay) } - - private fun MockKMatcherScope.intentFilterEq(value: Intent): Intent = - match { it.filterEquals(value) } } diff --git a/app/src/test/java/org/mozilla/fenix/ext/MockKMatcherScope.kt b/app/src/test/java/org/mozilla/fenix/ext/MockKMatcherScope.kt index 176a78b3c..6a49f0efe 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/MockKMatcherScope.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/MockKMatcherScope.kt @@ -1,5 +1,6 @@ package org.mozilla.fenix.ext +import android.content.Intent import androidx.navigation.NavDirections import io.mockk.Matcher import io.mockk.MockKMatcherScope @@ -11,6 +12,13 @@ import mozilla.components.support.ktx.android.os.contentEquals */ fun MockKMatcherScope.directionsEq(value: NavDirections) = match(EqNavDirectionsMatcher(value)) +/** + * Verify that two intents are the same for the purposes of intent resolution (filtering). + * Checks if their action, data, type, identity, class, and categories are the same. + * Does not compare extras. + */ +fun MockKMatcherScope.intentFilterEq(value: Intent) = match(EqIntentFilterMatcher(value)) + private data class EqNavDirectionsMatcher(private val value: NavDirections) : Matcher { override fun match(arg: NavDirections?): Boolean = @@ -19,3 +27,13 @@ private data class EqNavDirectionsMatcher(private val value: NavDirections) : Ma override fun substitute(map: Map) = copy(value = value.internalSubstitute(map)) } + +private data class EqIntentFilterMatcher(private val value: Intent) : Matcher { + + override fun match(arg: Intent?): Boolean = value.filterEquals(arg) + + override fun substitute(map: Map) = + copy(value = value.internalSubstitute(map)) + + override fun toString() = "intentFilterEq($value)" +} diff --git a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt index 2db0a9b94..aa67649dc 100644 --- a/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/DefaultSessionControlControllerTest.kt @@ -128,9 +128,21 @@ class DefaultSessionControlControllerTest { @Test fun handleDeleteCollectionTapped() { - val collection: TabCollection = mockk(relaxed = true) + val collection = mockk { + every { title } returns "Collection" + } + every { + activity.resources.getString(R.string.tab_collection_dialog_message, "Collection") + } returns "Are you sure you want to delete Collection?" + controller.handleDeleteCollectionTapped(collection) - verify { showDeleteCollectionPrompt(collection, null, any()) } + verify { + showDeleteCollectionPrompt( + collection, + null, + "Are you sure you want to delete Collection?" + ) + } } @Test diff --git a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt index c2fea785d..cd9b08ffe 100644 --- a/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/DefaultSearchControllerTest.kt @@ -4,6 +4,7 @@ package org.mozilla.fenix.search +import android.content.Intent import androidx.navigation.NavController import androidx.navigation.NavDirections import io.mockk.every @@ -24,7 +25,9 @@ import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.MetricController +import org.mozilla.fenix.crashes.CrashListActivity import org.mozilla.fenix.ext.components +import org.mozilla.fenix.ext.intentFilterEq import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.navigateSafe import org.mozilla.fenix.ext.searchEngineManager @@ -88,10 +91,13 @@ class DefaultSearchControllerTest { @Test fun handleCrashesUrlCommitted() { val url = "about:crashes" + every { activity.packageName } returns testContext.packageName controller.handleUrlCommitted(url) - verify { activity.startActivity(any()) } + verify { + activity.startActivity(intentFilterEq(Intent(testContext, CrashListActivity::class.java))) + } } @Test diff --git a/app/src/test/java/org/mozilla/fenix/search/telemetry/incontent/InContentTelemetryTest.kt b/app/src/test/java/org/mozilla/fenix/search/telemetry/incontent/InContentTelemetryTest.kt index 4714fe086..b491df390 100644 --- a/app/src/test/java/org/mozilla/fenix/search/telemetry/incontent/InContentTelemetryTest.kt +++ b/app/src/test/java/org/mozilla/fenix/search/telemetry/incontent/InContentTelemetryTest.kt @@ -61,7 +61,7 @@ class InContentTelemetryTest { telemetry.processMessage(message) - verify { telemetry.trackPartnerUrlTypeMetric(url, any()) } + verify { telemetry.trackPartnerUrlTypeMetric(url, listOf(first, second)) } } @Test diff --git a/app/src/test/java/org/mozilla/fenix/settings/deletebrowsingdata/DefaultDeleteBrowsingDataControllerTest.kt b/app/src/test/java/org/mozilla/fenix/settings/deletebrowsingdata/DefaultDeleteBrowsingDataControllerTest.kt index bf0cc524c..118edc67c 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/deletebrowsingdata/DefaultDeleteBrowsingDataControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/deletebrowsingdata/DefaultDeleteBrowsingDataControllerTest.kt @@ -54,7 +54,7 @@ class DefaultDeleteBrowsingDataControllerTest { controller.deleteBrowsingData() verify { - context.components.core.engine.clearData(any()) + context.components.core.engine.clearData(Engine.BrowsingData.select(Engine.BrowsingData.DOM_STORAGES)) context.components.core.historyStorage } }