Roman Elizarov | a7db8ec | 2017-12-21 22:45:12 +0300 | [diff] [blame] | 1 | /* |
Roman Elizarov | 1f74a2d | 2018-06-29 19:19:45 +0300 | [diff] [blame^] | 2 | * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. |
Roman Elizarov | a7db8ec | 2017-12-21 22:45:12 +0300 | [diff] [blame] | 3 | */ |
| 4 | |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 5 | package kotlinx.coroutines.experimental |
| 6 | |
Roman Elizarov | 9fe5f46 | 2018-02-21 19:05:52 +0300 | [diff] [blame] | 7 | import kotlin.coroutines.experimental.* |
Roman Elizarov | 9d5abcd | 2017-12-21 16:54:30 +0300 | [diff] [blame] | 8 | import kotlin.test.* |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 9 | |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 10 | class CoroutineExceptionHandlerTest : TestBase() { |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 11 | @Test |
Roman Elizarov | c0d71dc | 2017-12-21 22:12:43 +0300 | [diff] [blame] | 12 | fun testCoroutineExceptionHandlerCreator() = runTest { |
Roman Elizarov | 01d4125 | 2017-06-09 16:55:40 +0300 | [diff] [blame] | 13 | expect(1) |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 14 | var coroutineException: Throwable? = null |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 15 | val handler = CoroutineExceptionHandler { _, ex -> |
| 16 | coroutineException = ex |
Roman Elizarov | 01d4125 | 2017-06-09 16:55:40 +0300 | [diff] [blame] | 17 | expect(3) |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 18 | } |
Roman Elizarov | 43e3af7 | 2017-07-21 16:01:31 +0300 | [diff] [blame] | 19 | val job = launch(coroutineContext + handler) { |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 20 | throw TestException() |
| 21 | } |
Roman Elizarov | 01d4125 | 2017-06-09 16:55:40 +0300 | [diff] [blame] | 22 | expect(2) |
| 23 | job.join() |
| 24 | finish(4) |
Roman Elizarov | c0d71dc | 2017-12-21 22:12:43 +0300 | [diff] [blame] | 25 | assertTrue(coroutineException is TestException) |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 26 | } |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 27 | |
Roman Elizarov | 9d5abcd | 2017-12-21 16:54:30 +0300 | [diff] [blame] | 28 | private class TestException: RuntimeException() |
| 29 | } |