Created
April 17, 2023 14:38
-
-
Save belgoros/17bdfc20f78c84fb8d087e4fb5424c08 to your computer and use it in GitHub Desktop.
Ignore specific node values when using `JSONAssert.assertEquals`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testJsonArrayValues() throws JSONException { | |
String expectedJson = """ | |
{ | |
"messageElements": { | |
"messageStatus": "SUCCESS", | |
"businessCorrelationId": "a80337639eb40758", | |
"errorList": [] | |
}, | |
"data": [ | |
{ | |
"referenceId": 2, | |
"effectiveStartDate": "2021-01-08T00:00:00" | |
}, | |
{ | |
"referenceId": 2, | |
"effectiveStartDate": "2021-01-08T00:00:00" | |
} | |
] | |
} | |
"""; | |
String actualJson = """ | |
{ | |
"messageElements": { | |
"messageStatus": "SUCCESS", | |
"businessCorrelationId": "99999", | |
"errorList": [] | |
}, | |
"data": [ | |
{ | |
"referenceId": 2, | |
"effectiveStartDate": "2021-12-08T00:00:00" | |
}, | |
{ | |
"referenceId": 2, | |
"effectiveStartDate": "2021-12-08T00:00:00" | |
} | |
] | |
} | |
"""; | |
JSONAssert.assertEquals(expectedJson, actualJson, new CustomComparator(JSONCompareMode.LENIENT, | |
new Customization("data[*].effectiveStartDate", (ct1, ct2) -> true), | |
new Customization("messageElements.businessCorrelationId", (c1, c2) -> true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment