diff --git a/coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/HandleSafelyCoroutineContextTest.kt b/coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/HandleSafelyCoroutineContextTest.kt index 3c209b67357..b1c73d92843 100644 --- a/coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/HandleSafelyCoroutineContextTest.kt +++ b/coroutines/src/jvmTest/kotlin/dev/inmo/micro_utils/coroutines/HandleSafelyCoroutineContextTest.kt @@ -1,25 +1,20 @@ package dev.inmo.micro_utils.coroutines import kotlinx.coroutines.* +import kotlinx.coroutines.test.runTest import kotlin.test.Test class HandleSafelyCoroutineContextTest { @Test - fun testHandleSafelyCoroutineContext() { - val scope = CoroutineScope(Dispatchers.Default) + fun testHandleSafelyCoroutineContext() = runTest { + val scope = this var contextHandlerHappen = false var localHandlerHappen = false - var defaultHandlerHappen = false - defaultSafelyExceptionHandler = { - defaultHandlerHappen = true - throw it - } - val contextHandler: ExceptionHandler = { - contextHandlerHappen = true - } val checkJob = scope.launch { - safelyWithContextExceptionHandler(contextHandler) { - safely( + runCatchingLogging ({ + contextHandlerHappen = true + }) { + runCatchingLogging ( { localHandlerHappen = true } @@ -29,10 +24,8 @@ class HandleSafelyCoroutineContextTest { println(coroutineContext) error("That must happen too:)") } - } - launchSynchronously { checkJob.join() } + }.join() assert(contextHandlerHappen) assert(localHandlerHappen) - assert(defaultHandlerHappen) } } \ No newline at end of file