Fix potentially nondeterministic TestDeleteStory.testJsonSerialization #1546
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.
Issue
Hello, I noticed that the unit test
TestDeleteStory.testJsonSerializationrelies on a Jackson ObjectMapper to serialize thedeleteStoryobject. However, the ObjectMapper's JSON parameter ordering is technically not guaranteed without explicit configuration, thus the test can technically fail occasionally. Though it's likely stable now, it might be beneficial to address this just in case the underlying environment ends up changing in the future.This test was detected via by the Nondex tool, which flags Java tests that are potentially nondeterministic due to underlying assumptions regarding the Java API. To see the Nondex output for this test class, you can run:
Potential Fix
Jackson does provide some config options to set the parameter ordering in the ObjectMapper. Here, I configure the ObjectMapper to sort the parameters alphabetically using Jackson's
MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, and then I manually change the parameter ordering to alphabetical in the expected JSON string. I'm under the assumption the JSON parameter ordering doesn't matter for this unit test, but please let me know if that's not the case.The tests still pass (verified with
mvn clean test), and Nondex also shows a passing result now.There are a few other tests I found with a similar issue and fix, but I wanted to keep this PR very small to get some initial feedback and suggestions. Thank you!