diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/NullSafetyTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/NullSafetyTest.kt index 2adc1032bc..0ecc74b6fb 100644 --- a/kotlin/src/test/kotlin/com/baeldung/kotlin/NullSafetyTest.kt +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/NullSafetyTest.kt @@ -66,7 +66,27 @@ class NullSafetyTest { //when var res = listOf() for (item in names) { - item?.let { res = res.plus(it) } + item?.let { res = res.plus(it); it } + ?.also{it -> println("non nullable value: $it")} + } + + //then + assertEquals(2, res.size) + assertTrue { res.contains(firstName) } + assertTrue { res.contains(secondName) } + } + + @Test + fun fivenCollectionOfObject_whenUseRunOperator_thenExecuteActionOnNonNullValue(){ + //given + val firstName = "Tom" + val secondName = "Michael" + val names: List = listOf(firstName, null, secondName) + + //when + var res = listOf() + for (item in names) { + item?.run{res = res.plus(this)} } //then