-
Notifications
You must be signed in to change notification settings - Fork 7
/
CacheableValueTest.kt
38 lines (31 loc) · 1.14 KB
/
CacheableValueTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package io.embrace.android.embracesdk
import io.embrace.android.embracesdk.internal.CacheableValue
import org.junit.Assert.assertEquals
import org.junit.Test
internal class CacheableValueTest {
@Test
fun testCaching() {
var value = "test"
val cache = CacheableValue<String> { value }
assertEquals("test", cache.value { "test" })
assertEquals("test", cache.value { throw IllegalStateException() })
assertEquals("test", cache.value { throw IllegalStateException() })
value = "foo"
assertEquals("another", cache.value { "another" })
}
@Test
fun testHashcode() {
var value = -1
val cache = CacheableValue<Int> { value }
assertEquals(5, cache.value { 5 })
assertEquals(5, cache.value { throw IllegalStateException() })
assertEquals(5, cache.value { throw IllegalStateException() })
value = 79
assertEquals(22, cache.value { 22 })
}
@Test(expected = IllegalStateException::class)
fun testNullNotSupported() {
val cache = CacheableValue<String?> { "test" }
assertEquals("test", cache.value { null })
}
}