Skip to content

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

Description

@jfox13-nd

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions