Skip to content

Commit

Permalink
Add test for HandlerFunc with return value
Browse files Browse the repository at this point in the history
  • Loading branch information
janseeger committed Nov 8, 2023
1 parent 5166367 commit 0d09275
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
}

0 comments on commit 0d09275

Please sign in to comment.