Skip to content

Commit

Permalink
test: added common test cases for cache4k
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujin1135 committed Oct 11, 2024
1 parent cb36344 commit dfdfd56
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
15 changes: 14 additions & 1 deletion arrow-libs/core/arrow-cache4k/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -15,7 +16,7 @@ apply(from = property("ANIMALSNIFFER_MPP"))

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
languageVersion.set(JavaLanguageVersion.of(17))
}
}

Expand All @@ -29,6 +30,13 @@ kotlin {
api(libs.cache4k)
}
}
commonTest {
dependencies {
implementation(libs.kotlin.test)
implementation(libs.kotest.assertionsCore)
implementation(libs.coroutines.test)
}
}
}

jvm {
Expand Down Expand Up @@ -75,3 +83,8 @@ tasks.named<Jar>("jvmJar").configure {
attributes["Automatic-Module-Name"] = "arrow.cache4k"
}
}

// enables context receivers for Jvm Tests
tasks.named<KotlinCompile>("compileTestKotlinJvm") {
compilerOptions.freeCompilerArgs.add("-Xcontext-receivers")
}
Original file line number Diff line number Diff line change
@@ -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<String, Int>(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<String, Int>(buildCache4K { expireAfterAccess(Duration.INFINITE) })
val expectedKey = "user:name:userId:5"

cache.get(expectedKey) shouldBe null
}
}

0 comments on commit dfdfd56

Please sign in to comment.