Roman Elizarov | a7db8ec | 2017-12-21 22:45:12 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-2017 JetBrains s.r.o. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 17 | package kotlinx.coroutines.experimental |
| 18 | |
Roman Elizarov | 9fe5f46 | 2018-02-21 19:05:52 +0300 | [diff] [blame] | 19 | import kotlin.coroutines.experimental.* |
Roman Elizarov | 9d5abcd | 2017-12-21 16:54:30 +0300 | [diff] [blame] | 20 | import kotlin.test.* |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 21 | |
Roman Elizarov | aa461cf | 2018-04-11 13:20:29 +0300 | [diff] [blame] | 22 | class CoroutineExceptionHandlerTest : TestBase() { |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 23 | @Test |
Roman Elizarov | c0d71dc | 2017-12-21 22:12:43 +0300 | [diff] [blame] | 24 | fun testCoroutineExceptionHandlerCreator() = runTest { |
Roman Elizarov | 01d4125 | 2017-06-09 16:55:40 +0300 | [diff] [blame] | 25 | expect(1) |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 26 | var coroutineException: Throwable? = null |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 27 | val handler = CoroutineExceptionHandler { _, ex -> |
| 28 | coroutineException = ex |
Roman Elizarov | 01d4125 | 2017-06-09 16:55:40 +0300 | [diff] [blame] | 29 | expect(3) |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 30 | } |
Roman Elizarov | 43e3af7 | 2017-07-21 16:01:31 +0300 | [diff] [blame] | 31 | val job = launch(coroutineContext + handler) { |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 32 | throw TestException() |
| 33 | } |
Roman Elizarov | 01d4125 | 2017-06-09 16:55:40 +0300 | [diff] [blame] | 34 | expect(2) |
| 35 | job.join() |
| 36 | finish(4) |
Roman Elizarov | c0d71dc | 2017-12-21 22:12:43 +0300 | [diff] [blame] | 37 | assertTrue(coroutineException is TestException) |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 38 | } |
Konrad Kamiński | 5667bcf | 2017-05-30 15:34:03 +0200 | [diff] [blame] | 39 | |
Roman Elizarov | 9d5abcd | 2017-12-21 16:54:30 +0300 | [diff] [blame] | 40 | private class TestException: RuntimeException() |
| 41 | } |