Skip to content

Commit 6f75ad8

Browse files
tomekl007pivovarit
authored andcommitted
Bael 756 (eugenp#1531)
* BAEL-756 code for kotlin null-safety article * BAEL-756 fix typo * BAEL-756 increment version of Kotlin * BAEL-756 remove duplicate form pom * BAEL-756 add also and run example
1 parent e6d9dde commit 6f75ad8

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

‎kotlin/src/test/kotlin/com/baeldung/kotlin/NullSafetyTest.kt‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,27 @@ class NullSafetyTest {
6666
//when
6767
var res = listOf<String?>()
6868
for (item in names) {
69-
item?.let { res = res.plus(it) }
69+
item?.let { res = res.plus(it); it }
70+
?.also{it -> println("non nullable value: $it")}
71+
}
72+
73+
//then
74+
assertEquals(2, res.size)
75+
assertTrue { res.contains(firstName) }
76+
assertTrue { res.contains(secondName) }
77+
}
78+
79+
@Test
80+
fun fivenCollectionOfObject_whenUseRunOperator_thenExecuteActionOnNonNullValue(){
81+
//given
82+
val firstName = "Tom"
83+
val secondName = "Michael"
84+
val names: List<String?> = listOf(firstName, null, secondName)
85+
86+
//when
87+
var res = listOf<String?>()
88+
for (item in names) {
89+
item?.run{res = res.plus(this)}
7090
}
7191

7292
//then

0 commit comments

Comments
 (0)