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 f5c5cc5290
commit 2af1e30a8f
1 changed files with 20 additions and 0 deletions

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