From 647dbf2f98f9e152bbc93f10bdb4d0a2ac6379b7 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Tue, 2 Jun 2020 23:01:56 +0430 Subject: [PATCH] KTLN-141: Not-Null Assertion (!!) Operator in Kotlin (#9371) * Added the Test Samples * Renamed the Class --- .../nullassertion/NotNullAssertionUnitTest.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt b/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt new file mode 100644 index 0000000000..434f177927 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt @@ -0,0 +1,20 @@ +package com.baeldung.nullassertion + +import org.junit.Test +import kotlin.test.assertEquals + +class NotNullAssertionUnitTest { + + @Test + fun givenNullableValue_WhenNotNull_ShouldExtractTheValue() { + val answer: String? = "42" + + assertEquals(42, answer!!.toInt()) + } + + @Test(expected = KotlinNullPointerException::class) + fun givenNullableValue_WhenIsNull_ThenShouldThrow() { + val noAnswer: String? = null + noAnswer!! + } +}