Added The Sample Codes for Lateinit Initialization (#9253)

This commit is contained in:
Mona Mohamadinia 2020-05-10 13:34:01 +04:30 committed by GitHub
parent f7d9de0961
commit 8e5456b24b
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package com.baeldung.late
import org.junit.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class LateInitUnitTest {
private lateinit var answer: String
@Test(expected = UninitializedPropertyAccessException::class)
fun givenLateInit_WhenNotInitialized_ShouldThrowAnException() {
answer.length
}
@Test
fun givenLateInit_TheIsInitialized_ReturnsTheInitializationStatus() {
assertFalse { this::answer.isInitialized }
answer = "42"
assertTrue { this::answer.isInitialized }
}
}