assertk
assertk copied to clipboard
isNotNullOrEmpty() for Iterables
Currently the official way in the documentation is to first call .isNotNull() and then .isNotEmpty() . Can there be a new method that combines them? I know you can write a custom assertion but would be nice to have it built-in. Happy to open a pull request.
Example:
from:
val foo = listOf("hello", "world")
assertThat(foo).isNotNull().isNotEmpty()
to:
val foo = listOf("hello", "world")
assertThat(foo).isNotNullOrEmpty()
I don't think they should be combined. One is a general assertion which refines the type, whereas the other is an assertion on the contents of a collection.
I believe it could be treated as the inverted of isNullOrEmpty.
That assertion is impossible to otherwise represent though. It requires #450.
Asserting not null or empty is worded as not(null or empty) but that is logically equivalent to not(null) and not(empty). And and assertions are expressed separate functions because you can use as many in succession as you want.
Reasonable. It looks like isNullOrEmpty().not(), this might be why isNotNullOrEmpty hasn't been added to Kotlin stdlib.