From feb52ecbd1cc4a88d79738de06a57f3ed8202680 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 3 Mar 2025 19:40:45 +0600 Subject: [PATCH] fix of HandleSafelyCoroutineContextTest --- .../HandleSafelyCoroutineContextTest.kt | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) 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