public void testArbitrary_withCollisions() { List<Integer> list = Lists.newArrayList(); for (int i = 0; i < 50; i++) { list.add(i); } Ordering<Object> arbitrary = new ArbitraryOrdering() { @Override int identityHashCode(Object object) { return ((Integer) object) % 5; // fake tons of collisions! } }; // Don't let the elements be in such a predictable order list = shuffledCopy(list, new Random(1)); Collections.sort(list, arbitrary); // Now we don't care what order it's put the list in, only that // comparing any pair of elements gives the answer we expect. Helpers.testComparator(arbitrary, list); }