< prev index next >

test/tools/jlink/plugins/GetAvailableLocales.java

Print this page

        

@@ -21,22 +21,38 @@
  * questions.
  */
 
 import java.util.Arrays;
 import java.util.Locale;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.stream.Collectors;
 
 class GetAvailableLocales {
 
     public static void main(String[] args) {
-        String availableLocales = Arrays.stream(Locale.getAvailableLocales())
-            .map(l -> l.toString())
-            .sorted()
-            .collect(Collectors.joining(" "));
+        Set<String> expected = Set.of(args);
+        Set<String> actual =
+            Arrays.stream(Locale.getAvailableLocales())
+                  // "(root)" for Locale.ROOT rather than ""
+                  .map(loc -> loc.equals(Locale.ROOT) ? "(root)" : loc.toString())
+                  .collect(Collectors.toSet());
 
-        if (!availableLocales.equals(args[0])) {
-            throw new RuntimeException("Available locales are not equal to the expected ones.\n" +
-                "Expected: " + args[0] + "\n" +
-                "Actual:   " + availableLocales);
+        if (!expected.equals(actual)) {
+            diff(expected, actual);
+            System.exit(1);
+        }
+    }
+
+    private static void diff(Set<String> expected, Set<String> actual) {
+        Set<String> s1 = new TreeSet<>(expected);
+        s1.removeAll(actual);
+        if (!s1.isEmpty()) {
+            System.out.println("\tMissing locale(s): " + s1);
+        }
+        Set<String> s2 = new TreeSet<>(actual);
+        s2.removeAll(expected);
+        if (!s2.isEmpty()) {
+            System.out.println("\tExtra locale(s): " + s2);
         }
     }
 }
< prev index next >