From 5166367214201a21519577ee65cf76c964a3ab78 Mon Sep 17 00:00:00 2001 From: Jan Seeger Date: Wed, 8 Nov 2023 22:36:32 +0100 Subject: [PATCH] Fix AndroidHandlerFunc tests --- dachlatten-compose/build.gradle.kts | 12 ++++++++++++ .../src/test/kotlin/AndroidHandlerFuncTest.kt | 11 ++++++----- gradle/libs.versions.toml | 3 ++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dachlatten-compose/build.gradle.kts b/dachlatten-compose/build.gradle.kts index 4d7eff8..cad801b 100644 --- a/dachlatten-compose/build.gradle.kts +++ b/dachlatten-compose/build.gradle.kts @@ -1,9 +1,21 @@ plugins { id("android-library-base") id("android-library-unit-test") + id("android-library-robolectric-test") id("android-library-release") } dependencies { implementation(libs.compose.ui) } + +android { + composeOptions { + kotlinCompilerExtensionVersion = libs.versions.compose.compiler.get() + } + + buildFeatures { + compose = true + } +} + diff --git a/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt b/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt index 3ad7f61..0f8534d 100644 --- a/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt +++ b/dachlatten-compose/src/test/kotlin/AndroidHandlerFuncTest.kt @@ -1,15 +1,16 @@ package de.sipgate.dachlatten.compose -import android.content.Context -import org.junit.jupiter.api.Test +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +@RunWith(RobolectricTestRunner::class) class AndroidHandlerFuncTest { - private lateinit var context: Context - @Test fun testAndroidHandlerFuncWillReceiveAContext() { - + val context = RuntimeEnvironment.getApplication().applicationContext val handlerFunc = context.withContext(::someFunctionThatAccessesTheAndroidContext) handlerFunc.invoke() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6b9cb3d..2fe9530 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -8,7 +8,8 @@ turbine = "1.0.0" annotation-jvm = "1.7.0" androidx-lifecycle = "2.6.2" robolectric = "4.10.3" -compose = "1.5.3" +compose = "1.5.4" +compose-compiler = "1.5.4" [libraries] coroutines = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" }