Use LinkedHashMap for a deterministic iteration order in DependencyUtil.java

Description

The tests in liquibase.util.DependencyUtilTest#testIndependentBranchesCase can fail due to a different iteration order of HashMap. The assertion failure is presented as follows:
java.lang.AssertionError:
expected:<a, o, x, b, p1, p2, y, c1, c2, r1, r2, s, s2, s3>
but was:<x, a, o, y, b, p1, p2, c1, c2, r1, r2, s, s2, s3>
at liquibase.util.DependencyUtilTest.testIndependentBranchesCase(DependencyUtilTest.java:79)

The root cause of this assertion failure lies in the variable nodes in DependencyUtil.java , which is a HashMap. The specification about HashMap says that "this class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time". The documentation is here for your reference: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html

The fix is to change it to a LinkedHashMap so that the iteration order remains stable and the failure will not occur any more. In this way, the test will be more stable.

Environment

Ubuntu Jdk8

Reporter

3132425812

Affects versions

Priority

Minor
Configure