-
Notifications
You must be signed in to change notification settings - Fork 3
Is not empty should be false when a node is missing #54
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #54 +/- ##
============================================
+ Coverage 97.54% 97.58% +0.03%
- Complexity 490 496 +6
============================================
Files 64 64
Lines 856 869 +13
Branches 64 64
============================================
+ Hits 835 848 +13
Misses 12 12
Partials 9 9 ☔ View full report in Codecov by Sentry. |
| */ | ||
| default A isNotEmpty() { | ||
| return satisfies(not(new IsEmpty())); | ||
| return satisfies(not(MissingCondition.getInstance()).and(not(new IsEmpty()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does the job for missing nodes, but what about null values ? It feels wrong that assertJson("{\"prop\": null}").at("/prop").isNotEmpty(); passes.
| return satisfies(not(MissingCondition.getInstance()).and(not(new IsEmpty()))); | |
| return satisfies(not(MissingCondition.getInstance())..and(not(NullCondition.getInstance())).and(not(new IsEmpty()))); |
| } | ||
|
|
||
|
|
||
| @Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@test
void isNotEmptyOnNullIsFalse() {
assertAllWays("{"count":0}", "{"count": null}",
assertion -> assertion.at("/count").isNotEmpty());
}
|
@lmartelli - I think you're right. I've pushed another extension to the code. See what you think. |
|
Looks good to me. But I wonder if it's a good think to allow checking for emptyness for all value types. It does not really mean anything for booleans or integers. |
|
@lmartelli - given that everything in JSON is an I'd be happy that Realistically, it's on the user not to use Have you a counter proposal? By the way, I'm appreciating having someone to discuss these ideas with and shape the tool. |
|
I encountered the issue because I used I am not very comfortable with |
|
@lmartelli I took the spirit of your point and I've implemented something deeper. I also found out that the README recommended the use of more assertions than just It recommended: assertJson(foo)
.at("/path").isText()
.at("/path").isEmpty();or assertJson(foo)
.at("/path").isText()
.at("/path").isNotEmpty();I've now made it so that This means that the preferred route is: assertJson(foo)
.at("/path").text().isNotEmpty();And the But I've left the shortcuts in place, with a deprecation on I think this allows the shorthand, which is convenient, but also more heavily recommends a stronger-typed approach, which is clearer. I don't like I need to do this for Boolean and Numeric node DSLs too... but give me early feedback. |
|
@lmartelli - thanks for your input. I've done some further refactoring to make this new approach make sense. This might be a breaking change for some users. I'll get this released in due course. |
…ons up to core dsl
a900bf1 to
cf1f8c3
Compare
Possible fix for #53
@lmartelli - please review and let me know what you think?