harshith2000 opened a new pull request, #1131:
URL: https://github.com/apache/commons-lang/pull/1131

   Found two non-deterministic tests failing in EnumUtilsTest.java 
   Test names: 
[test_getEnumMap](https://github.com/apache/commons-lang/blob/912ab7154d5280a2632f375b5efd97e1b70149a4/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java#L341),
 
[test_getEnumMap_keyFunction](https://github.com/apache/commons-lang/blob/912ab7154d5280a2632f375b5efd97e1b70149a4/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java#L355)
   
   ### Reason for failure: 
   The issue we're encountering in the test arises from the nature of the Map 
collection in Java. The Map returned by the getEnumMap method does not 
guarantee the order of its elements. 
   
https://github.com/apache/commons-lang/blob/912ab7154d5280a2632f375b5efd97e1b70149a4/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java#L342
   This is especially true when you're using implementations like HashMap, 
which is what Collectors.toMap() typically uses under the hood. According to 
the [official 
documentation](https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html),
 HashMap does not maintain the order of its elements.
   
https://github.com/apache/commons-lang/blob/912ab7154d5280a2632f375b5efd97e1b70149a4/src/main/java/org/apache/commons/lang3/EnumUtils.java#L301
   
   ### Fix: 
   Instead of converting the [test 
map](https://github.com/apache/commons-lang/blob/912ab7154d5280a2632f375b5efd97e1b70149a4/src/test/java/org/apache/commons/lang3/EnumUtilsTest.java#L343)
 to a string, and then doing an assert check, we can create an expected Map and 
then compare the two maps. This way, we check whether both maps have the same 
key-value pairs, but don't consider the order in which these elements are 
stored.
   
   ### Steps to reproduce the behavior:
   I used an open-source tool called 
[NonDex](https://github.com/TestingResearchIllinois/NonDex) to detect the 
assumption by shuffling the order of returned exception types.
   Running the following commands will test the aforementioned operation
   
   **Clone the Repo**
   ```
   https://github.com/apache/commons-lang 
   ```
   **Compile the project**
   ```
   mvn install -am -DskipTests
   ```
   **(Optional) Run the unit test**
   ```
   mvn test 
-Dtest=org.apache.commons.lang3.EnumUtilsTest#test_getEnumMap_keyFunction
   ```
   **Run the unit test using NonDex**
   ```
   mvn edu.illinois:nondex-maven-plugin:2.1.1:nondex 
-Dtest=org.apache.commons.lang3.EnumUtilsTest#test_getEnumMap_keyFunction
   ```
   
   ### Stack trace for additional information:
   ```
   [ERROR] Failures: 
   [ERROR]   EnumUtilsTest.test_getEnumMap:343 getEnumMap not created correctly 
==> expected: <{RED=RED, AMBER=AMBER, GREEN=GREEN}> but was: <{GREEN=GREEN, 
RED=RED, AMBER=AMBER}>
   [ERROR]   EnumUtilsTest.test_getEnumMap_keyFunction:357 getEnumMap not 
created correctly ==> expected: <{1=JAN, 2=FEB, 3=MAR, 4=APR, 5=MAY, 6=JUN, 
7=JUL, 8=AUG, 9=SEP, 10=OCT, 11=NOV, 12=DEC}> but was: <{8=AUG, 1=JAN, 10=OCT, 
12=DEC, 2=FEB, 7=JUL, 6=JUN, 11=NOV, 3=MAR, 5=MAY, 9=SEP, 4=APR}>
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to