Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isNotNullOrEmpty() for Iterables #512

Open
josetorrs opened this issue Jan 17, 2024 · 4 comments
Open

isNotNullOrEmpty() for Iterables #512

josetorrs opened this issue Jan 17, 2024 · 4 comments

Comments

@josetorrs
Copy link

josetorrs commented Jan 17, 2024

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()
@JakeWharton
Copy link
Contributor

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.

@Goooler
Copy link
Contributor

Goooler commented Mar 3, 2024

I believe it could be treated as the inverted of isNullOrEmpty.

@JakeWharton
Copy link
Contributor

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.

@Goooler
Copy link
Contributor

Goooler commented Mar 9, 2024

Reasonable. It looks like isNullOrEmpty().not(), this might be why isNotNullOrEmpty hasn't been added to Kotlin stdlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants