From d5f975dbfe21fe62261b6b0eff4e8aadfe49cd07 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Sun, 10 May 2020 13:34:01 +0430 Subject: [PATCH] Added The Sample Codes for Lateinit Initialization (#9253) --- .../com/baeldung/late/LateInitUnitTest.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt new file mode 100644 index 0000000000..c99e438742 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt @@ -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 } + } +}