Finished fixing the test that is broken in Java 1.8.

Finished fixing the test that is broken in Java 1.8 due to being
sensitive to the iteration order of elements in a HashSet. There were
multiple problems that needed to be fixed. My earlier commit only
fixed the first problem.