diff --git a/arrow-libs/core/arrow-cache4k/build.gradle.kts b/arrow-libs/core/arrow-cache4k/build.gradle.kts index f73ae851bd2..fdd073733a0 100644 --- a/arrow-libs/core/arrow-cache4k/build.gradle.kts +++ b/arrow-libs/core/arrow-cache4k/build.gradle.kts @@ -2,6 +2,7 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.KotlinVersion +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { @@ -15,7 +16,7 @@ apply(from = property("ANIMALSNIFFER_MPP")) java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + languageVersion.set(JavaLanguageVersion.of(17)) } } @@ -29,6 +30,13 @@ kotlin { api(libs.cache4k) } } + commonTest { + dependencies { + implementation(libs.kotlin.test) + implementation(libs.kotest.assertionsCore) + implementation(libs.coroutines.test) + } + } } jvm { @@ -75,3 +83,8 @@ tasks.named("jvmJar").configure { attributes["Automatic-Module-Name"] = "arrow.cache4k" } } + +// enables context receivers for Jvm Tests +tasks.named("compileTestKotlinJvm") { + compilerOptions.freeCompilerArgs.add("-Xcontext-receivers") +} diff --git a/arrow-libs/core/arrow-cache4k/src/commonTest/kotlin/arrow/core/Cache4kTest.kt b/arrow-libs/core/arrow-cache4k/src/commonTest/kotlin/arrow/core/Cache4kTest.kt new file mode 100644 index 00000000000..3e0277d4262 --- /dev/null +++ b/arrow-libs/core/arrow-cache4k/src/commonTest/kotlin/arrow/core/Cache4kTest.kt @@ -0,0 +1,25 @@ +package arrow.core + +import io.kotest.matchers.shouldBe +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.time.Duration + +class Cache4kTest { + + @Test fun cacheShouldReturnSavedValueByKeyCorrectly() = runTest { + val cache = Cache4kMemoizationCache(buildCache4K { expireAfterAccess(Duration.INFINITE) }) + val expectedKey = "user:age:userId:5" + val expectedValue = 32 + + cache.set(expectedKey, expectedValue) + cache.get(expectedKey) shouldBe expectedValue + } + + @Test fun cacheShouldReturnNullCauseTryGetByUnsavedKey() = runTest { + val cache = Cache4kMemoizationCache(buildCache4K { expireAfterAccess(Duration.INFINITE) }) + val expectedKey = "user:name:userId:5" + + cache.get(expectedKey) shouldBe null + } +}