The third command shows us the flakiness in the test. There are test failures due to differences in the order of elements
Source of Flakiness in the test and fix:
The object rootEntities is a set and sets in Java have no order. However, the check being carried out was - assertThat(rootEntities, contains(cls, valueEntity));
The contains() method checks if the two objects cls and valueEntity are present in the exact order in which they are mentioned and this fails if the order in the set is different from the order mentioned.
To fix this, contains() is replaced by hasItems() which does not check the order of items.
A flaky test was fixed in this pull request-
Flakiness in the tests -
To check for flakiness in the tests, a tool called nondex was used.
Steps to reproduce flakiness using nondex -
Test 1:
The third command shows us the flakiness in the test. There are test failures due to differences in the order of elements
Source of Flakiness in the test and fix: The object rootEntities is a set and sets in Java have no order. However, the check being carried out was - assertThat(rootEntities, contains(cls, valueEntity)); The contains() method checks if the two objects cls and valueEntity are present in the exact order in which they are mentioned and this fails if the order in the set is different from the order mentioned.
To fix this, contains() is replaced by hasItems() which does not check the order of items.
Code change- assertThat(rootEntities, hasItems(cls, valueEntity));
Please let me know if you have any questions or need any additional justification/changes from my side.