33 lines
720 B
Kotlin
33 lines
720 B
Kotlin
package net.shadowfacts.cacao.util.properties
|
|
|
|
import org.junit.jupiter.api.Assertions.*
|
|
import org.junit.jupiter.api.Test
|
|
import java.util.concurrent.CompletableFuture
|
|
|
|
/**
|
|
* @author shadowfacts
|
|
*/
|
|
class ObservableLateInitPropertyTests {
|
|
|
|
class MyClass(callback: (String) -> Unit) {
|
|
val delegate = ObservableLateInitProperty(callback)
|
|
var prop by delegate
|
|
}
|
|
|
|
@Test
|
|
fun testObservation() {
|
|
val future = CompletableFuture<String>()
|
|
val obj = MyClass { future.complete(it) }
|
|
obj.prop = "test"
|
|
assertEquals("test", future.getNow(null))
|
|
}
|
|
|
|
@Test
|
|
fun testIsInitialized() {
|
|
val obj = MyClass {}
|
|
assertFalse(obj.delegate.isInitialized)
|
|
obj.prop = "test"
|
|
assertTrue(obj.delegate.isInitialized)
|
|
}
|
|
|
|
} |