Skip to content

Commit

Permalink
Fix assertion by json array similar method
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <daichen@amazon.com>
  • Loading branch information
dai-chen committed Apr 26, 2023
1 parent 92e2a7e commit 7b8aef3
Showing 1 changed file with 1 addition and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,30 +231,7 @@ public void describeTo(Description description) {

@Override
protected boolean matchesSafely(JSONArray array) {
if (array.length() != expectedObjects.length) {
return false;
}

for (int i = 0; i < expectedObjects.length; i++) {
Object expected = expectedObjects[i];
boolean isEqual;

// Use similar() because JSONObject/JSONArray.equals() only check if same reference
if (expected instanceof JSONObject) {
isEqual = ((JSONObject) expected).similar(array.get(i));
} else if (expected instanceof JSONArray) {
isEqual = ((JSONArray) expected).similar(array.get(i));
} else if (null == expected) {
isEqual = JSONObject.NULL == array.get(i);
} else {
isEqual = expected.equals(array.get(i));
}

if (!isEqual) {
return false;
}
}
return true;
return array.similar(new JSONArray(expectedObjects));
}
};
}
Expand Down

0 comments on commit 7b8aef3

Please sign in to comment.