blob: 2025422dfb7c1dc1c989d79697eba2841b40c272 (
plain)
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
|
package ca.allanwang.kau.kotlin
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
/**
* Created by Allan Wang on 2017-07-29.
*
* Test code for [LazyResettable]
*/
class LazyResettableTest {
lateinit var registry: LazyResettableRegistry
@Before
fun init() {
registry = LazyResettableRegistry()
}
@Test
fun basic() {
val timeDelegate = lazyResettable { System.currentTimeMillis() }
val time: Long by timeDelegate
registry.add(timeDelegate)
val t1 = time
Thread.sleep(5)
val t2 = time
registry.invalidateAll()
Thread.sleep(5)
val t3 = time
assertEquals(t1, t2, "Lazy resettable not returning same value after second call")
assertNotEquals(t1, t3, "Lazy resettable not invalidated by registry")
}
}
|