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

fix: fixed JSON order independent comparison in DefaultFactoryTest #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Qi-Cui
Copy link
Owner

@Qi-Cui Qi-Cui commented Sep 6, 2024

Description

Test org.apache.gora.mongodb.filters.DefaultFactoryTest#testCreateFilter_list_2 occasionally fails when the order of fields in the JSONObject objects is different. The current test compares the two JSONObject objects by converting them to strings, which is order-sensitive, and could fail when field order differs.

Steps to reproduce

Run mvn -pl gora-mongodb edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=org.apache.gora.mongodb.filters.DefaultFactoryTest#testCreateFilter_list_2 -DnondexRuns=10.

Expected Behaviour

This test should pass consistently, regardless of the order of fields in the JSONObject, as long as the content remains the same.

Actual Behaviour

The test occasionally fails, raise an exception with error message:

DefaultFactoryTest.testCreateFilter_list_2:119 expected:<{"[h.C·T":"text/html","url":"http://www.example.com]"}> but was:<{"[url":"http://www.example.com","h.C·T":"text/html]"}>

Proposed Solution

The solution is to parse both expected and actual JSONObject into JsonNode, rather than comparing them as strings. Then use Jackson's ObjectMapper to compare the two JsonNode objects, which ignores the order of the keys.

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

Successfully merging this pull request may close these issues.

1 participant