diff --git a/selekt-java/src/test/kotlin/com/bloomberg/selekt/LruCacheTest.kt b/selekt-java/src/test/kotlin/com/bloomberg/selekt/cache/LruCacheTest.kt similarity index 76% rename from selekt-java/src/test/kotlin/com/bloomberg/selekt/LruCacheTest.kt rename to selekt-java/src/test/kotlin/com/bloomberg/selekt/cache/LruCacheTest.kt index 7f7692499d..7679080144 100644 --- a/selekt-java/src/test/kotlin/com/bloomberg/selekt/LruCacheTest.kt +++ b/selekt-java/src/test/kotlin/com/bloomberg/selekt/cache/LruCacheTest.kt @@ -14,9 +14,8 @@ * limitations under the License. */ -package com.bloomberg.selekt +package com.bloomberg.selekt.cache -import com.bloomberg.selekt.cache.LruCache import org.junit.jupiter.api.Test import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.doReturn @@ -30,8 +29,42 @@ import org.mockito.kotlin.whenever import kotlin.test.assertFalse import kotlin.test.assertSame import kotlin.test.assertTrue +import kotlin.test.fail internal class LruCacheTest { + @Test + fun get() { + val first = Any() + val disposal: (Any) -> Unit = mock { onGeneric { invoke(it) } doReturn Unit } + val cache = LruCache(1, disposal) + cache["1", { first }] + assertSame(first, cache["1", { fail() }]) + } + + @Test + fun getTwo() { + val first = Any() + val second = Any() + val disposal: (Any) -> Unit = mock { onGeneric { invoke(it) } doReturn Unit } + val cache = LruCache(2, disposal) + cache["1", { first }] + cache["2", { second }] + assertSame(first, cache["1", { fail() }]) + assertSame(second, cache["2", { fail() }]) + } + + @Test + fun getAfterEvict() { + val first = Any() + val second = Any() + val disposal: (Any) -> Unit = mock { onGeneric { invoke(it) } doReturn Unit } + val cache = LruCache(1, disposal) + cache["1", { first }] + cache["2", { second }] + assertFalse(cache.containsKey("1")) + assertSame(second, cache["2", { fail() }]) + } + @Test fun evict() { val first = Any() @@ -44,6 +77,7 @@ internal class LruCacheTest { inOrder(disposal) { verify(disposal, times(1)).invoke(same(first)) } + assertSame(second, cache["2", { fail() }]) } @Test