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

Update JSONPointerTest for NonDex compatibility #696

Merged
merged 1 commit into from Oct 15, 2022

Conversation

bmk15897
Copy link
Contributor

Description

Flaky Test found using NonDex by running the command -
mvn edu.illinois:nondex-maven-plugin:1.1.2:nondex -Dtest=org.json.junit.JSONPointerTest#queryByEmptyKeySubObject

The logged failure for the org.json.junit.JSONPointerTest.queryByEmptyKeySubObject -

[ERROR] Failures: 
[ERROR]   JSONPointerTest.queryByEmptyKeySubObject:75 expected:<{"[":"empty key of an object with an empty key","subKey":"Some other value]"}> but was:<{"[subKey":"Some other value","":"empty key of an object with an empty key]"}>

Investigation

The test fails at JSONPointerTest.queryByEmptyKeySubObject:75 with a comparison error while comparing an expected string and the result from org.json.junit.JSONPointerTest.query function after converting it into String. The toString function of the Object class makes no guarantees as to the iteration order of the attributes in the object. This makes the test outcome non-deterministic and the test fails whenever the toString changes the order of the properties. To fix this, the expected and actual values should be checked in a more deterministic way so that the assertions do not fail.

Fix

Expected and Actual values can be converted into JSONObject and the similar can be used to compare these objects. As this function compares the values inside the JSONObjects without needing order, the test becomes deterministic and ensures that the flakiness from the test is removed.

The PR does not introduce a breaking change.

@stleary
Copy link
Owner

stleary commented Oct 13, 2022

What problem does this code solve?
Fixes a unit test that is broken when running with Nondex

Risks
Low

Changes to the API?
N/A

Will this require a new release?
No

Should the documentation be updated?
No

Does it break the unit tests?
No

Was any code refactored in this commit?
N/A

Review status
APPROVED

Starting 3-day comment window

@stleary stleary changed the title Fix Flaky Test Update JSONPointerTest for NonDex compatibility Oct 14, 2022
@stleary stleary merged commit 98df354 into stleary:master Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants