Bael 756 (#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
This commit is contained in:
parent
e6d9dde931
commit
6f75ad86a6
|
@ -66,7 +66,27 @@ class NullSafetyTest {
|
||||||
//when
|
//when
|
||||||
var res = listOf<String?>()
|
var res = listOf<String?>()
|
||||||
for (item in names) {
|
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
|
//then
|
||||||
|
|
Loading…
Reference in New Issue