tor-browser

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

commit 8d31013d644c426af64ba730b15d071100967e04
parent 4ecb5beb8b20be55fa378dc638616a7899d8bea7
Author: mcarare <48995920+mcarare@users.noreply.github.com>
Date:   Thu, 20 Nov 2025 15:53:06 +0000

Bug 2001329 - Refactor ExceptionHandlerTest to use runTest r=android-reviewers,giorga

This patch updates `ExceptionHandlerTest` to use `runTest` instead of `MainCoroutineRule` for handling coroutines in tests.

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

Diffstat:
Mmobile/android/android-components/components/lib/crash/src/test/java/mozilla/components/lib/crash/handler/ExceptionHandlerTest.kt | 20+++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/mobile/android/android-components/components/lib/crash/src/test/java/mozilla/components/lib/crash/handler/ExceptionHandlerTest.kt b/mobile/android/android-components/components/lib/crash/src/test/java/mozilla/components/lib/crash/handler/ExceptionHandlerTest.kt @@ -5,6 +5,7 @@ package mozilla.components.lib.crash.handler import androidx.test.ext.junit.runners.AndroidJUnit4 +import kotlinx.coroutines.test.runTest import mozilla.components.concept.base.crash.Breadcrumb import mozilla.components.lib.crash.Crash import mozilla.components.lib.crash.CrashReporter @@ -13,10 +14,7 @@ import mozilla.components.support.test.any import mozilla.components.support.test.eq import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext -import mozilla.components.support.test.rule.MainCoroutineRule import org.junit.Assert.assertArrayEquals -import org.junit.Ignore -import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.doThrow @@ -27,12 +25,8 @@ import org.mockito.Mockito.verify @RunWith(AndroidJUnit4::class) class ExceptionHandlerTest { - @get:Rule - val coroutinesTestRule = MainCoroutineRule() - private val scope = coroutinesTestRule.scope - @Test - fun `ExceptionHandler forwards crashes to CrashReporter`() { + fun `ExceptionHandler forwards crashes to CrashReporter`() = runTest { val service: CrashReporterService = mock() val crashReporter = spy( @@ -40,7 +34,7 @@ class ExceptionHandlerTest { context = testContext, shouldPrompt = CrashReporter.Prompt.NEVER, services = listOf(service), - scope = scope, + scope = this, ), ) @@ -57,7 +51,7 @@ class ExceptionHandlerTest { } @Test - fun `ExceptionHandler invokes default exception handler`() { + fun `ExceptionHandler invokes default exception handler`() = runTest { val defaultExceptionHandler: Thread.UncaughtExceptionHandler = mock() val crashReporter = CrashReporter( @@ -78,7 +72,7 @@ class ExceptionHandlerTest { override fun report(throwable: Throwable, breadcrumbs: ArrayList<Breadcrumb>): String? = null }, ), - scope = scope, + scope = this, ).install(testContext) val handler = ExceptionHandler( @@ -96,7 +90,7 @@ class ExceptionHandlerTest { } @Test - fun `exceptions in CrashReporter invoke default exception handler`() { + fun `exceptions in CrashReporter invoke default exception handler`() = runTest { val defaultExceptionHandler: Thread.UncaughtExceptionHandler = mock() val crashReporter = spy( @@ -118,7 +112,7 @@ class ExceptionHandlerTest { override fun report(throwable: Throwable, breadcrumbs: ArrayList<Breadcrumb>): String? = null }, ), - scope = scope, + scope = this, ), ) val reporterException = RuntimeException("CrashReporterException")