KTLN-141: Not-Null Assertion (!!) Operator in Kotlin (#9371)
* Added the Test Samples * Renamed the Class
This commit is contained in:
parent
f5c5cc5290
commit
2af1e30a8f
@ -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!!
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user