Fix flaky test UtilTest.testEnhanceResponseWithShippingAddressList #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of changes:
This PR aims to fix a test:
This was found by using the NonDex tool.
REASON AND FIX
Encountered the following error while using NonDex:
The tests fails when the function
testEnhanceResponseWithShippingAddressList()
compares both strings (expectedCheckoutSessionResponse.RawResponse and actualCheckoutSessionResponseAfterEnhancing.RawResponse) with key-value pairs in it.The JSON object is unordered since it uses Maps as their internal data structure. According to documentation,
"This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time."
Due to this a non-deterministic order of key-value pairs are maintained and hence the assertEquals fails.
amazon-pay-api-sdk-java/tst/com/amazon/pay/api/UtilTest.java
Line 257 in 3ff564e
One possible solution is to have those strings as JSONObjects and check using JSONObject.similar(), which compares if the contents of two JSON objects are the same, perhaps having a different order of attributes.
amazon-pay-api-sdk-java/tst/com/amazon/pay/api/UtilTest.java
Lines 257 to 259 in ff493ba
Reproduce:
This was found by using the NonDex tool.
The following command can be used to replicate the failures and validate the fix:
Environment:
No user-facing change.
No dependency upgrade.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.