blob: 19437cda859029227f88b4de847b509afd7fa496 [file] [log] [blame]
Roman Elizarova7db8ec2017-12-21 22:45:12 +03001/*
Roman Elizarov1f74a2d2018-06-29 19:19:45 +03002 * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
Roman Elizarova7db8ec2017-12-21 22:45:12 +03003 */
4
Konrad Kamiński5667bcf2017-05-30 15:34:03 +02005package kotlinx.coroutines.experimental
6
Roman Elizarov9fe5f462018-02-21 19:05:52 +03007import kotlin.coroutines.experimental.*
Roman Elizarov9d5abcd2017-12-21 16:54:30 +03008import kotlin.test.*
Konrad Kamiński5667bcf2017-05-30 15:34:03 +02009
Roman Elizarovaa461cf2018-04-11 13:20:29 +030010class CoroutineExceptionHandlerTest : TestBase() {
Konrad Kamiński5667bcf2017-05-30 15:34:03 +020011 @Test
Roman Elizarovc0d71dc2017-12-21 22:12:43 +030012 fun testCoroutineExceptionHandlerCreator() = runTest {
Roman Elizarov01d41252017-06-09 16:55:40 +030013 expect(1)
Konrad Kamiński5667bcf2017-05-30 15:34:03 +020014 var coroutineException: Throwable? = null
Konrad Kamiński5667bcf2017-05-30 15:34:03 +020015 val handler = CoroutineExceptionHandler { _, ex ->
16 coroutineException = ex
Roman Elizarov01d41252017-06-09 16:55:40 +030017 expect(3)
Konrad Kamiński5667bcf2017-05-30 15:34:03 +020018 }
Roman Elizarov43e3af72017-07-21 16:01:31 +030019 val job = launch(coroutineContext + handler) {
Konrad Kamiński5667bcf2017-05-30 15:34:03 +020020 throw TestException()
21 }
Roman Elizarov01d41252017-06-09 16:55:40 +030022 expect(2)
23 job.join()
24 finish(4)
Roman Elizarovc0d71dc2017-12-21 22:12:43 +030025 assertTrue(coroutineException is TestException)
Konrad Kamiński5667bcf2017-05-30 15:34:03 +020026 }
Konrad Kamiński5667bcf2017-05-30 15:34:03 +020027
Roman Elizarov9d5abcd2017-12-21 16:54:30 +030028 private class TestException: RuntimeException()
29}