@@ -16,15 +16,6 @@ import io.sentry.ISentryExecutorService
1616import io.sentry.SentryLevel
1717import io.sentry.test.DeferredExecutorService
1818import io.sentry.test.ImmediateExecutorService
19- import java.util.concurrent.CountDownLatch
20- import kotlin.test.AfterTest
21- import kotlin.test.BeforeTest
22- import kotlin.test.Test
23- import kotlin.test.assertEquals
24- import kotlin.test.assertFalse
25- import kotlin.test.assertNotNull
26- import kotlin.test.assertNull
27- import kotlin.test.assertTrue
2819import org.junit.runner.RunWith
2920import org.mockito.kotlin.any
3021import org.mockito.kotlin.anyOrNull
@@ -41,6 +32,15 @@ import org.robolectric.annotation.Config
4132import org.robolectric.shadow.api.Shadow
4233import org.robolectric.shadows.ShadowActivityManager
4334import org.robolectric.shadows.ShadowBuild
35+ import java.util.concurrent.CountDownLatch
36+ import kotlin.test.AfterTest
37+ import kotlin.test.BeforeTest
38+ import kotlin.test.Test
39+ import kotlin.test.assertEquals
40+ import kotlin.test.assertFalse
41+ import kotlin.test.assertNotNull
42+ import kotlin.test.assertNull
43+ import kotlin.test.assertTrue
4444
4545@RunWith(AndroidJUnit4 ::class )
4646@Config(sdk = [Build .VERSION_CODES .TIRAMISU ])
@@ -52,6 +52,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
5252 lateinit var shadowActivityManager: ShadowActivityManager
5353
5454 fun getSut (
55+ contextForSut : Context = context,
5556 enableSystemEventBreadcrumbs : Boolean = true,
5657 enableSystemEventBreadcrumbsExtras : Boolean = false,
5758 executorService : ISentryExecutorService = ImmediateExecutorService (),
@@ -64,7 +65,7 @@ class SystemEventsBreadcrumbsIntegrationTest {
6465 this .executorService = executorService
6566 }
6667 return SystemEventsBreadcrumbsIntegration (
67- context ,
68+ contextForSut ,
6869 SystemEventsBreadcrumbsIntegration .getDefaultActions().toTypedArray(),
6970 handler,
7071 )
@@ -313,6 +314,20 @@ class SystemEventsBreadcrumbsIntegrationTest {
313314 assertFalse(fixture.options.isEnableSystemEventBreadcrumbs)
314315 }
315316
317+ @Test
318+ fun `Do not crash if receiver already unregistered` () {
319+ val realContext = ApplicationProvider .getApplicationContext<Context >()
320+ val sut = fixture.getSut(realContext)
321+
322+ sut.register(fixture.scopes, fixture.options)
323+
324+ realContext.unregisterReceiver(sut.receiver)
325+
326+ val result = runCatching { sut.onBackground() }
327+
328+ assertFalse(result.isFailure)
329+ }
330+
316331 @Test
317332 fun `when str has full package, return last string after dot` () {
318333 val sut = fixture.getSut()
@@ -421,9 +436,9 @@ class SystemEventsBreadcrumbsIntegrationTest {
421436 sut.register(fixture.scopes, fixture.options)
422437
423438 Thread {
424- sut.close()
425- latch.countDown()
426- }
439+ sut.close()
440+ latch.countDown()
441+ }
427442 .start()
428443
429444 latch.await()
@@ -505,9 +520,9 @@ class SystemEventsBreadcrumbsIntegrationTest {
505520 assertNotNull(sut.receiver)
506521
507522 Thread {
508- sut.close()
509- latch.countDown()
510- }
523+ sut.close()
524+ latch.countDown()
525+ }
511526 .start()
512527
513528 latch.await()
0 commit comments