assertj: null is not blank?!
Summary
As far as I know, null is considered as “Blank” (as “Blank” is superset of null, empty string or blank characters only)
Example
This passes:
String s = null;
assertThat(s).isNotBlank();
Java 8 specific ?
- NO : create Pull Request from the
2.xbranch
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 17 (12 by maintainers)
Commits related to this issue
- #1069 - Fix up javadoc for isBlank() — committed to ChrisCanCompute/assertj-core by deleted user 7 years ago
- #1069 Add isStrictlyBlank and isNotStrictlyBlank — committed to ChrisCanCompute/assertj-core by deleted user 7 years ago
- #1069 Add isStrictlyBlank and isNotStrictlyBlank — committed to ChrisCanCompute/assertj-core by deleted user 7 years ago
- #1069 - Fix up javadoc for isBlank() — committed to ChrisCanCompute/assertj-core by ChrisCanCompute 7 years ago
- #1069 - Fix up javadoc for isBlank() — committed to ChrisCanCompute/assertj-core by ChrisCanCompute 7 years ago
- #1069 - Fix up javadoc for isBlank() — committed to ChrisCanCompute/assertj-core by ChrisCanCompute 7 years ago
- #1069 Add isStrictlyBlank and isNotStrictlyBlank — committed to ChrisCanCompute/assertj-core by ChrisCanCompute 7 years ago
Ok. It looks like the spec is cleared up now. I’ll abandon my pull requests and fix this tomorrow unless anyone has any further comments?
@joel-costigliola I think the by far most common use-case is
isNotBlankand use it to check that a string is notnull, empty or whitespace only (as reported by eximius313). So if we makeisNotBlankfail fornull, it should also fail for an empty string.I’m not a great fan of
isStricklyBlank. ImhocontainsOnlyWhitespacewould be a more intention revealing name ( it also similar to the existing methodcontainsOnlyDigits), but I doubt somebody needs this assertion (I could be wrong of course 😉).containsNotOnlyWhitespacewould be clearer thatisNotStrictlyBlank, what do you think?I’m o.k. with replacing the more correct whitespace definition with the java one, as most users probably do not care either way (but because of this I also do not see a strong reason to change it).
I’m going to add both
isStrictlyBlank()andisNotStrictlyBlank()for completeness 😃