Loading components/lib/crash/src/test/java/mozilla/components/lib/crash/CrashReporterTest.kt +18 −8 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ import android.content.Intent import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineScope import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.support.test.any import mozilla.components.support.test.eq Loading @@ -34,12 +36,14 @@ import org.robolectric.Robolectric import org.robolectric.Shadows.shadowOf import java.lang.reflect.Modifier @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) class CrashReporterTest { private val testDispatcher = TestCoroutineDispatcher() private val scope = TestCoroutineScope(testDispatcher) @ExperimentalCoroutinesApi @get:Rule val coroutinesTestRule = MainCoroutineRule() val coroutinesTestRule = MainCoroutineRule(testDispatcher) @Before fun setUp() { Loading Loading @@ -72,7 +76,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.NEVER shouldPrompt = CrashReporter.Prompt.NEVER, scope = scope ).install(testContext)) val crash: Crash.UncaughtExceptionCrash = mock() Loading @@ -91,7 +96,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ALWAYS shouldPrompt = CrashReporter.Prompt.ALWAYS, scope = scope ).install(testContext)) val crash: Crash.UncaughtExceptionCrash = mock() Loading @@ -110,7 +116,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH, scope = scope ).install(testContext)) val crash: Crash.UncaughtExceptionCrash = mock() Loading @@ -129,7 +136,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH, scope = scope ).install(testContext)) val crash: Crash.NativeCodeCrash = mock() Loading Loading @@ -158,7 +166,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ALWAYS shouldPrompt = CrashReporter.Prompt.ALWAYS, scope = scope ).install(testContext)) reporter.enabled = false Loading @@ -178,7 +187,8 @@ class CrashReporterTest { val service = mock<CrashReporterService>() val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.NEVER shouldPrompt = CrashReporter.Prompt.NEVER, scope = scope ).install(testContext)) doReturn(mock<Job>()).`when`(reporter).submitReport(crash) Loading components/lib/crash/src/test/java/mozilla/components/lib/crash/handler/ExceptionHandlerTest.kt +15 −2 Original line number Diff line number Diff line Loading @@ -5,23 +5,34 @@ package mozilla.components.lib.crash.handler import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineScope import mozilla.components.lib.crash.Crash import mozilla.components.lib.crash.CrashReporter import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.support.test.any import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.fail import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.never import org.mockito.Mockito.spy import org.mockito.Mockito.verify @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) class ExceptionHandlerTest { private val testDispatcher = TestCoroutineDispatcher() private val scope = TestCoroutineScope(testDispatcher) @get:Rule val coroutinesTestRule = MainCoroutineRule(testDispatcher) @Test fun `ExceptionHandler forwards crashes to CrashReporter`() { Loading @@ -42,7 +53,8 @@ class ExceptionHandlerTest { val crashReporter = spy(CrashReporter( shouldPrompt = CrashReporter.Prompt.NEVER, services = listOf(service) services = listOf(service), scope = scope )) val handler = ExceptionHandler( Loading Loading @@ -77,7 +89,8 @@ class ExceptionHandlerTest { override fun report(throwable: Throwable) { } }) }), scope = scope ).install(testContext) val handler = ExceptionHandler( Loading components/lib/crash/src/test/java/mozilla/components/lib/crash/prompt/CrashReporterActivityTest.kt +14 −3 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ActivityScenario.launch import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineScope import kotlinx.coroutines.test.runBlockingTest import mozilla.components.lib.crash.Crash Loading @@ -24,10 +25,12 @@ import mozilla.components.lib.crash.prompt.CrashReporterActivity.Companion.SHARE import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock Loading @@ -37,6 +40,11 @@ import org.mockito.MockitoAnnotations.initMocks @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) class CrashReporterActivityTest { private val testDispatcher = TestCoroutineDispatcher() private val scope = TestCoroutineScope(testDispatcher) @get:Rule val coroutinesTestRule = MainCoroutineRule(testDispatcher) @Mock lateinit var service: CrashReporterService Loading @@ -50,7 +58,8 @@ class CrashReporterActivityTest { fun `Pressing close button sends report`() = runBlockingTest { CrashReporter( shouldPrompt = CrashReporter.Prompt.ALWAYS, services = listOf(service) services = listOf(service), scope = scope ).install(testContext) val crash = Crash.UncaughtExceptionCrash(RuntimeException("Hello World"), arrayListOf()) Loading @@ -72,7 +81,8 @@ class CrashReporterActivityTest { fun `Pressing restart button sends report`() = runBlockingTest { CrashReporter( shouldPrompt = CrashReporter.Prompt.ALWAYS, services = listOf(service) services = listOf(service), scope = scope ).install(testContext) val crash = Crash.UncaughtExceptionCrash(RuntimeException("Hello World"), arrayListOf()) Loading Loading @@ -114,7 +124,8 @@ class CrashReporterActivityTest { fun `Sending crash report saves checkbox state`() = runBlockingTest { CrashReporter( shouldPrompt = CrashReporter.Prompt.ALWAYS, services = listOf(service) services = listOf(service), scope = scope ).install(testContext) val crash = Crash.UncaughtExceptionCrash(RuntimeException("Hello World"), arrayListOf()) Loading Loading
components/lib/crash/src/test/java/mozilla/components/lib/crash/CrashReporterTest.kt +18 −8 Original line number Diff line number Diff line Loading @@ -10,6 +10,8 @@ import android.content.Intent import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineScope import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.support.test.any import mozilla.components.support.test.eq Loading @@ -34,12 +36,14 @@ import org.robolectric.Robolectric import org.robolectric.Shadows.shadowOf import java.lang.reflect.Modifier @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) class CrashReporterTest { private val testDispatcher = TestCoroutineDispatcher() private val scope = TestCoroutineScope(testDispatcher) @ExperimentalCoroutinesApi @get:Rule val coroutinesTestRule = MainCoroutineRule() val coroutinesTestRule = MainCoroutineRule(testDispatcher) @Before fun setUp() { Loading Loading @@ -72,7 +76,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.NEVER shouldPrompt = CrashReporter.Prompt.NEVER, scope = scope ).install(testContext)) val crash: Crash.UncaughtExceptionCrash = mock() Loading @@ -91,7 +96,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ALWAYS shouldPrompt = CrashReporter.Prompt.ALWAYS, scope = scope ).install(testContext)) val crash: Crash.UncaughtExceptionCrash = mock() Loading @@ -110,7 +116,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH, scope = scope ).install(testContext)) val crash: Crash.UncaughtExceptionCrash = mock() Loading @@ -129,7 +136,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH shouldPrompt = CrashReporter.Prompt.ONLY_NATIVE_CRASH, scope = scope ).install(testContext)) val crash: Crash.NativeCodeCrash = mock() Loading Loading @@ -158,7 +166,8 @@ class CrashReporterTest { val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.ALWAYS shouldPrompt = CrashReporter.Prompt.ALWAYS, scope = scope ).install(testContext)) reporter.enabled = false Loading @@ -178,7 +187,8 @@ class CrashReporterTest { val service = mock<CrashReporterService>() val reporter = spy(CrashReporter( services = listOf(service), shouldPrompt = CrashReporter.Prompt.NEVER shouldPrompt = CrashReporter.Prompt.NEVER, scope = scope ).install(testContext)) doReturn(mock<Job>()).`when`(reporter).submitReport(crash) Loading
components/lib/crash/src/test/java/mozilla/components/lib/crash/handler/ExceptionHandlerTest.kt +15 −2 Original line number Diff line number Diff line Loading @@ -5,23 +5,34 @@ package mozilla.components.lib.crash.handler import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineScope import mozilla.components.lib.crash.Crash import mozilla.components.lib.crash.CrashReporter import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.support.test.any import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule import org.junit.Assert.assertEquals import org.junit.Assert.assertNotNull import org.junit.Assert.fail import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.never import org.mockito.Mockito.spy import org.mockito.Mockito.verify @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) class ExceptionHandlerTest { private val testDispatcher = TestCoroutineDispatcher() private val scope = TestCoroutineScope(testDispatcher) @get:Rule val coroutinesTestRule = MainCoroutineRule(testDispatcher) @Test fun `ExceptionHandler forwards crashes to CrashReporter`() { Loading @@ -42,7 +53,8 @@ class ExceptionHandlerTest { val crashReporter = spy(CrashReporter( shouldPrompt = CrashReporter.Prompt.NEVER, services = listOf(service) services = listOf(service), scope = scope )) val handler = ExceptionHandler( Loading Loading @@ -77,7 +89,8 @@ class ExceptionHandlerTest { override fun report(throwable: Throwable) { } }) }), scope = scope ).install(testContext) val handler = ExceptionHandler( Loading
components/lib/crash/src/test/java/mozilla/components/lib/crash/prompt/CrashReporterActivityTest.kt +14 −3 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ import androidx.test.core.app.ActivityScenario import androidx.test.core.app.ActivityScenario.launch import androidx.test.ext.junit.runners.AndroidJUnit4 import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.TestCoroutineDispatcher import kotlinx.coroutines.test.TestCoroutineScope import kotlinx.coroutines.test.runBlockingTest import mozilla.components.lib.crash.Crash Loading @@ -24,10 +25,12 @@ import mozilla.components.lib.crash.prompt.CrashReporterActivity.Companion.SHARE import mozilla.components.lib.crash.service.CrashReporterService import mozilla.components.support.test.mock import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.rule.MainCoroutineRule import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock Loading @@ -37,6 +40,11 @@ import org.mockito.MockitoAnnotations.initMocks @ExperimentalCoroutinesApi @RunWith(AndroidJUnit4::class) class CrashReporterActivityTest { private val testDispatcher = TestCoroutineDispatcher() private val scope = TestCoroutineScope(testDispatcher) @get:Rule val coroutinesTestRule = MainCoroutineRule(testDispatcher) @Mock lateinit var service: CrashReporterService Loading @@ -50,7 +58,8 @@ class CrashReporterActivityTest { fun `Pressing close button sends report`() = runBlockingTest { CrashReporter( shouldPrompt = CrashReporter.Prompt.ALWAYS, services = listOf(service) services = listOf(service), scope = scope ).install(testContext) val crash = Crash.UncaughtExceptionCrash(RuntimeException("Hello World"), arrayListOf()) Loading @@ -72,7 +81,8 @@ class CrashReporterActivityTest { fun `Pressing restart button sends report`() = runBlockingTest { CrashReporter( shouldPrompt = CrashReporter.Prompt.ALWAYS, services = listOf(service) services = listOf(service), scope = scope ).install(testContext) val crash = Crash.UncaughtExceptionCrash(RuntimeException("Hello World"), arrayListOf()) Loading Loading @@ -114,7 +124,8 @@ class CrashReporterActivityTest { fun `Sending crash report saves checkbox state`() = runBlockingTest { CrashReporter( shouldPrompt = CrashReporter.Prompt.ALWAYS, services = listOf(service) services = listOf(service), scope = scope ).install(testContext) val crash = Crash.UncaughtExceptionCrash(RuntimeException("Hello World"), arrayListOf()) Loading