--- old/test/jdk/java/util/Formatter/FormatLocale.java 2018-02-22 12:32:21.220570643 +0530 +++ new/test/jdk/java/util/Formatter/FormatLocale.java 2018-02-22 12:32:20.764570643 +0530 @@ -1,5 +1,5 @@ /* - * 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 @@ -23,9 +23,12 @@ /** * @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 */ @@ -50,40 +53,80 @@ "%S", "%S", "%TB", - "%G"); + "%G", + "%C"); + static final List src = List.of( "Turkish", "Turkish", LocalDate.of(2016, Month.APRIL, 1), - Float.valueOf(100_000_000)); + Float.valueOf(100_000_000), + 'i'); + + static final List defaultLocale = List.of( + Locale.ENGLISH, + TURKISH, + TURKISH, + Locale.FRANCE, + TURKISH); + static final List formatLocale = List.of( - Locale.ENGLISH, - TURKISH, - TURKISH, - Locale.FRANCE); - static final List expected = List.of( - "TURKISH", - "TURK\u0130SH", - "N\u0130SAN", - "1,00000E+08"); + TURKISH, + Locale.ENGLISH, + Locale.FRANCE, + Locale.ENGLISH, + Locale.ENGLISH); + + static final List expectedWithDefaultLocale = List.of( + "TURKISH", + "TURK\u0130SH", + "N\u0130SAN", + "1,00000E+08", + "\u0130"); + + static final List 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 " - + formatLocale.get(i) + - ". Expected: " + expected.get(i) + - " Returned: " + sb.toString()); + "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: " + expectedWithFormatLocale.get(i) + + " Returned: " + sb.toString()); + } + }); + } static void nullLocaleTest() {