KTLN-141: Not-Null Assertion (!!) Operator in Kotlin (#9371)

* Added the Test Samples

* Renamed the Class
This commit is contained in:
Mona Mohamadinia
2020-06-02 23:01:56 +04:30
committed by GitHub
parent 0603a73a58
commit 647dbf2f98

View File

@@ -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!!
}
}