-
Notifications
You must be signed in to change notification settings - Fork 3
Add option to allow empty array to match null #58
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
base: main
Are you sure you want to change the base?
Conversation
|
Hey @lmartelli - this seems like a very specific condition. It's an unexpectedly specific one. I wonder whether we should implement this differently. Can you give me some more context. What's the problem we're trying to solve here? We have an expected JSON that contains Can we do this another way? Should we be saying that |
My context is verifying interaction with a service that happens to replace @Test
void can_add_exception() {
Map<String, String> urlException = Map.of(
"path", "/toto",
"comment", "bla bla");
assertThat(siteApi.urlExceptions().post(urlException))
.isSuccess()
.hasStatus(CREATED);
verifyUrlExceptions(List.of(urlException));}
@Test
void can_delete_exception() {
val urlExceptionId =
siteApi.urlExceptions().post(
Map.of("path", "/toto", "comment", "bla bla"),
IdDto.class)
.assertSuccess()
.getBody()
.getId();
assertThat(siteApi.urlExceptions(urlExceptionId).delete())
.hasStatus(NO_CONTENT);
verifyUrlExceptions(emptyList());
}
private void verifyUrlExceptions(List<Map<String, String>> urlExceptions) {
assertThat(siteApi.urlExceptions().getArray()).hasJsonBody(urlExceptions);
if (urlExceptions.isEmpty())
assertThatSiteIsProvisionedWith(assertJson -> assertJson.at("/urlsException").satisfies(new IsEmpty().or(NullCondition.getInstance())));
else
assertThatSiteIsProvisionedWith(Map.of("urlsException", map(urlExceptions, get("path"))));
}
private void assertThatSiteIsProvisionedWith(Object expected) {
assertThat(shieldProvClient.getSiteConfig(siteName))
.hasValueSatisfying(prov -> assertJson(prov).isEqualTo(expected));
}
private void assertThatSiteIsProvisionedWith(UnaryOperator<AssertJson<Object>> assertions) {
assertThat(shieldProvClient.getSiteConfig(siteName))
.hasValueSatisfying(prov -> assertions.apply(JsonAssertions.assertJson(prov)));
}Needless to say, I have other fields to check. With nullMatchesEmptyArray(), I could get rid of
This is my current workaround as you can see, but I was not able to write |
|
I could probably convert |
|
Not that easy :-( |
|
I now have a better solution in my tests, but still when the service will eventually return a proper |
|
I think we could reasonably have an The I think we can do more work to make the composing of conditions a bit easier too, since your current test code has to work hard to make the I didn't have the static code I was talking about in my comment. I was just expressing in pseudocode the intention here. What do you think is the highest priority useful change we can make from all the examples discussed so far? |
|
Static methods to allow for more natural and concise conditions in satisfies looks like a good low hanging fruit to catch. |
|
@lmartelli - if you want to do that, then be my guest. Maybe add some sort of Conditions class where these methods can appear in the bit of the package which is meant to be the public interface. The readme says that the internals aren't guaranteed for long-term compatibility, but that there are public entry points which are. |
|
@lmartelli - the trail's gone cold on this - what's your view on the way forward? |
No description provided.