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

Custom Comparators do not behave as expected when dealing with certain regular expressions that contain JSON Arrays #161

Open
jfox13-nd opened this issue Mar 6, 2022 · 0 comments

Comments

@jfox13-nd
Copy link

jfox13-nd commented Mar 6, 2022

When using a CustomComparator based on a RegularExpressionValueMatcher to match values of the type foo[*].bar.baz the CustomComparator will be disregarded in the NON_EXTENSIBLE and LENIENT modes.

Here is a minimal example that will throw two AssertionErrors:

        String expected = "{\"addresses\": [ {\"address\": {\"num\": \"not_a_number\"} } ] }";
        String actual =   "{\"addresses\": [ {\"address\": {\"num\": \"not_a_number\"} } ] }";

        // Correctly checks that there are number values at addresses[*].address.num
        JSONAssert.assertNotEquals(expected, actual,
                new CustomComparator(
                        JSONCompareMode.STRICT,
                        new Customization("addresses[*].address.num",
                                new RegularExpressionValueMatcher<Object>("\\d"))));

        // Fails to check that a number value exists at addresses[*].address.num
        JSONAssert.assertNotEquals(expected, actual,
                new CustomComparator(
                        JSONCompareMode.NON_EXTENSIBLE,
                        new Customization("addresses[*].address.num",
                                new RegularExpressionValueMatcher<Object>("\\d"))));

        // Fails to check that a number value exists at addresses[*].address.num
        JSONAssert.assertNotEquals(expected, actual,
                new CustomComparator(
                        JSONCompareMode.LENIENT,
                        new Customization("addresses[*].address.num",
                                new RegularExpressionValueMatcher<Object>("\\d"))));

I have created a PR that fixes this edge case:
#160

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

No branches or pull requests

1 participant