• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.android
6 
7 import kotlinx.coroutines.*
8 import org.junit.Test
9 import org.junit.runner.*
10 import org.robolectric.*
11 import org.robolectric.annotation.*
12 import kotlin.test.*
13 
14 @RunWith(RobolectricTestRunner::class)
15 @Config(manifest = Config.NONE, sdk = [27])
16 @LooperMode(LooperMode.Mode.LEGACY)
17 class AndroidExceptionPreHandlerTest : TestBase() {
18     @Test
19     fun testUnhandledException() = runTest {
20         val previousHandler = Thread.getDefaultUncaughtExceptionHandler()
21         try {
22             Thread.setDefaultUncaughtExceptionHandler { _, e ->
23                 expect(3)
24                 assertIs<TestException>(e)
25             }
26             expect(1)
27             GlobalScope.launch(Dispatchers.Main) {
28                 expect(2)
29                 throw TestException()
30             }.join()
31             finish(4)
32         } finally {
33             Thread.setDefaultUncaughtExceptionHandler(previousHandler)
34         }
35     }
36 }
37