* 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
This commit is contained in:
Tomasz Lelek 2017-03-29 13:41:37 +02:00 committed by Grzegorz Piwowarek
parent e6d9dde931
commit 6f75ad86a6
1 changed files with 21 additions and 1 deletions

View File

@ -66,7 +66,27 @@ class NullSafetyTest {
//when
var res = listOf<String?>()
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<String?> = listOf(firstName, null, secondName)
//when
var res = listOf<String?>()
for (item in names) {
item?.run{res = res.plus(this)}
}
//then