Skip to content

Conversation

@anthonyx24
Copy link

Issue

Hello, I noticed that the unit test TestDeleteStory.testJsonSerialization relies on a Jackson ObjectMapper to serialize the deleteStory object. 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:

mvn -pl telegrambots-meta edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest="org.telegram.telegrambots.meta.api.methods.stories.TestDeleteStory"

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant