https://kotlinlang.org logo
Title
a

adam-mcneilly

08/29/2018, 1:22 PM
The
assertFalse
function in Kotlin test requires a non null boolean. What is the most idiomatic way to handle a nullable boolean?
assertFalse(condition ?: true)
is one. We could also invert it and say
assertTrue(condition == false)
but honestly I wish I could just pass a nullable boolean. I'm not sure why we couldn't.
s

spand

08/29/2018, 1:26 PM
I would prefer the latter of the two. Maybe its because I use hamkrest where its just
assertThat(condition, equalTo(false))
👍 1
g

gildor

08/29/2018, 5:49 PM
You can define own assertFalse that concider null as false, if it make sense for your usecase. But it shouldn't be default behavior Also official style guide recommends to use == instead of ?: for nullable booleans