void () { final Map<String, String> keysValues = generateKeyValues(KEYS_COUNT, MAX_KEY_VALUE_SIZE); final List<String> keys = keysValues.keySet().stream().toList(); final List<List<? extends String>> sortedKeys = new ArrayList<>(); for (int i = 0; i < ENOUGH_SHUFFLE_TRIES; i++) { final List<String> keysCopy = new ArrayList<>(keys); Collections.shuffle(keysCopy); final List<String> sorted = sorter.apply(keysCopy); sortedKeys.add(sorted); } assertEquals( "Stable sort must produce same sorted list, regardless of initial order of items", 1, new HashSet<>(sortedKeys).size() ); }