< prev index next >

test/jdk/java/util/Formatter/FormatLocale.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -21,13 +21,16 @@
  * questions.
  */
 
 /**
  * @test
- * @bug 8146156 8159548
+ * @bug 8146156 8159548 8060094
  * @modules jdk.localedata
  * @summary test whether uppercasing follows Locale.Category.FORMAT locale.
+ *          Also test whether the uppercasing uses the locale specified to the
+ *          Formatter API.
+ *
  * @run main/othervm FormatLocale
  */
 
 import java.time.LocalDate;
 import java.time.ZonedDateTime;

@@ -48,44 +51,84 @@
 
     static final List<String> conversions = List.of(
         "%S",
         "%S",
         "%TB",
-        "%G");
+        "%G",
+        "%C");
+
     static final List<Object> src = List.of(
         "Turkish",
         "Turkish",
         LocalDate.of(2016, Month.APRIL, 1),
-        Float.valueOf(100_000_000));
-    static final List<Locale> formatLocale = List.of(
+        Float.valueOf(100_000_000),
+        'i');
+
+    static final List<Locale> defaultLocale = List.of(
         Locale.ENGLISH,
         TURKISH,
         TURKISH,
-        Locale.FRANCE);
-    static final List<String> expected = List.of(
+            Locale.FRANCE,
+            TURKISH);
+
+    static final List<Locale> formatLocale = List.of(
+            TURKISH,
+            Locale.ENGLISH,
+            Locale.FRANCE,
+            Locale.ENGLISH,
+            Locale.ENGLISH);
+
+    static final List<String> expectedWithDefaultLocale = List.of(
         "TURKISH",
         "TURK\u0130SH",
         "N\u0130SAN",
-        "1,00000E+08");
+            "1,00000E+08",
+            "\u0130");
+
+    static final List<String> expectedWithFormatLocale = List.of(
+            "TURK\u0130SH",
+            "TURKISH",
+            "AVRIL",
+            "1.00000E+08",
+            "I");
 
     static void formatLocaleTest() {
         StringBuilder sb = new StringBuilder();
 
+        // checks whether upper casing follows Locale.Category.FORMAT locale
         IntStream.range(0, src.size()).forEach(i -> {
             sb.setLength(0);
-            Locale.setDefault(Locale.Category.FORMAT, formatLocale.get(i));
+            Locale.setDefault(Locale.Category.FORMAT, defaultLocale.get(i));
             new Formatter(sb).format(conversions.get(i), src.get(i));
-            if (!sb.toString().equals(expected.get(i))) {
+            if (!sb.toString().equals(expectedWithDefaultLocale.get(i))) {
+                throw new RuntimeException(
+                        "Wrong uppercasing with Formatter.format(" +
+                                "\"" + conversions.get(i) + "\"" +
+                                ") in locale "
+                                + defaultLocale.get(i) +
+                                ". Expected: " + expectedWithDefaultLocale.get(i) +
+                                " Returned: " + sb.toString());
+            }
+        });
+
+        // checks whether upper casing uses the locale set during creation of
+        // Formatter instance, instead of the default locale.
+        IntStream.range(0, src.size()).forEach(i -> {
+            sb.setLength(0);
+            Locale.setDefault(Locale.Category.FORMAT, defaultLocale.get(i));
+            new Formatter(sb, formatLocale.get(i)).format(conversions.get(i), src.get(i));
+            if (!sb.toString().equals(expectedWithFormatLocale.get(i))) {
                 throw new RuntimeException(
                     "Wrong uppercasing with Formatter.format(" +
                     "\"" + conversions.get(i) + "\"" +
                     ") in locale "
                     + formatLocale.get(i) +
-                    ". Expected: " + expected.get(i) +
+                                ". Expected: " + expectedWithFormatLocale.get(i) +
                     " Returned: " + sb.toString());
             }
         });
+
     }
 
     static void nullLocaleTest() {
         String fmt = "%1$ta %1$tA %1$th %1$tB %1tZ";
         String expected = "Fri Friday Jan January PST";
< prev index next >