Add Kotlin extensions for Cache and CacheManager
See gh-23927
This commit is contained in:
committed by
Stephane Nicoll
parent
24cb1def7d
commit
5ec1e20242
31
spring-context/src/test/kotlin/org/springframework/cache/CacheExtensionsTest.kt
vendored
Normal file
31
spring-context/src/test/kotlin/org/springframework/cache/CacheExtensionsTest.kt
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
package org.springframework.cache
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager
|
||||
|
||||
class CacheExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `Check inline get variant`() {
|
||||
val cache = createCache()
|
||||
cache.put("k", "v")
|
||||
assertEquals("v", cache.get<String>("k"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Check operator get variant`() {
|
||||
val cache = createCache()
|
||||
cache.put("k", "v")
|
||||
assertEquals("v", cache["k"]?.get() as String?)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Check operator set variant`() {
|
||||
val cache = createCache()
|
||||
cache["k"] = "v"
|
||||
assertEquals("v", cache.get("k", String::class.java))
|
||||
}
|
||||
|
||||
private fun createCache(cacheName: String = "c"): Cache = ConcurrentMapCacheManager(cacheName).getCache(cacheName)!!
|
||||
}
|
||||
16
spring-context/src/test/kotlin/org/springframework/cache/CacheManagerExtensionsTest.kt
vendored
Normal file
16
spring-context/src/test/kotlin/org/springframework/cache/CacheManagerExtensionsTest.kt
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
package org.springframework.cache
|
||||
|
||||
import org.junit.jupiter.api.Assertions.assertNotEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager
|
||||
|
||||
class CacheManagerExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `Check operator get variant`() {
|
||||
val cm = createCacheManager("c")
|
||||
assertNotEquals(null, cm["c"])
|
||||
}
|
||||
|
||||
private fun createCacheManager(cacheName: String = "c"): CacheManager = ConcurrentMapCacheManager(cacheName)
|
||||
}
|
||||
Reference in New Issue
Block a user