Fix a non-deterministic assertion in ServletUtilsTest #4981
+3
−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
Problem: The test io.swagger.v3.jaxrs2.util.ServletUtilsTest.convertWithRightOutputSize can fail intermittently because multivaluedMap.keySet() does not guarantee the order of the keys.This non-deterministic behavior was detected using the NonDex tool. This pull request is for a simple fix to make the test deterministic.
Reference: https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/MultivaluedHashMap.html
Fixes: This PR replaces the order-dependent assertion with a robust check that verifies the presence of the expected keys. By using assertTrue(multivaluedMap.containsKey("key1")) and assertTrue(multivaluedMap.containsKey("key2")), the test correctly validates the map's contents without relying on iteration order, making it deterministic and reliable.
Type of Change
Checklist
Screenshots / Additional Context
Log from NonDex:
[ERROR] Failures:
[ERROR] ServletUtilsTest.convertWithRightOutputSize:29 expected [key1] but found [key2]
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0