From 0d0927546d7886e15c4d5c4b00ceeb00d8696363 Mon Sep 17 00:00:00 2001 From: Jan Seeger Date: Wed, 8 Nov 2023 22:41:46 +0100 Subject: [PATCH] Add test for HandlerFunc with return value --- .../src/test/kotlin/AndroidHandlerFuncTest.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt b/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt index 0f8534d..d20a53c 100644 --- a/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt +++ b/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt @@ -1,6 +1,7 @@ package de.sipgate.dachlatten.compose import org.junit.Test +import org.junit.jupiter.api.Assertions import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.RuntimeEnvironment @@ -16,8 +17,22 @@ class AndroidHandlerFuncTest { handlerFunc.invoke() } + @Test + fun testAndroidHandlerFuncWillReceiveAContextAndReturnValueIsPassedBack() { + val context = RuntimeEnvironment.getApplication().applicationContext + val handlerFunc = context.withContext(::someFunctionThatAccessesTheAndroidContextAndReturnsSomething) + + val result = handlerFunc.invoke() + Assertions.assertTrue(result.isNotEmpty()) + } + context (ContextProvider) private fun someFunctionThatAccessesTheAndroidContext() { - context.applicationInfo.name + context.packageName + } + + context (ContextProvider) + private fun someFunctionThatAccessesTheAndroidContextAndReturnsSomething(): String { + return context.packageName } }