--- /dev/null 2019-07-31 15:52:04.000000000 -0700 +++ new/test/jdk/java/util/Locale/bcp47u/CurrencyFormatTests.java 2019-07-31 15:52:04.000000000 -0700 @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2019, 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. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * + * @test + * @bug 8215181 + * @summary Tests the "u-cf" extension + * @modules jdk.localedata + * @run testng/othervm CurrencyFormatTests + */ + +import static org.testng.Assert.assertEquals; + +import java.text.NumberFormat; +import java.util.Locale; + +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Test NumberFormat with BCP47 u-cf extensions. Note that this test depends + * on the particular CLDR release. Results may vary on other CLDR releases. + */ +@Test +public class CurrencyFormatTests { + + @DataProvider(name="getInstanceData") + Object[][] getInstanceData() { + return new Object[][] { + // Locale, amount, expected + // US dollar + {Locale.US, -100, "-$100.00"}, + {Locale.forLanguageTag("en-US-u-cf-standard"), -100, "-$100.00"}, + {Locale.forLanguageTag("en-US-u-cf-account"), -100, "($100.00)"}, + {Locale.forLanguageTag("en-US-u-cf-bogus"), -100, "-$100.00"}, + + // Euro + {Locale.forLanguageTag("en-AT"), -100, "-\u20ac\u00a0100,00"}, + {Locale.forLanguageTag("en-AT-u-cf-standard"), -100, "-\u20ac\u00a0100,00"}, + {Locale.forLanguageTag("en-AT-u-cf-account"), -100, "-\u20ac\u00a0100,00"}, + {Locale.forLanguageTag("en-AT-u-cf-bogus"), -100, "-\u20ac\u00a0100,00"}, + + // Rupee + {Locale.forLanguageTag("en-IN"), -100, "-\u20b9\u00a0100.00"}, + {Locale.forLanguageTag("en-IN-u-cf-standard"), -100, "-\u20b9\u00a0100.00"}, + {Locale.forLanguageTag("en-IN-u-cf-account"), -100, "(\u20b9100.00)"}, + {Locale.forLanguageTag("en-IN-u-cf-bogus"), -100, "-\u20b9\u00a0100.00"}, + + // Swiss franc + {Locale.forLanguageTag("en-CH"), -100, "CHF-100.00"}, + {Locale.forLanguageTag("en-CH-u-cf-standard"), -100, "CHF-100.00"}, + {Locale.forLanguageTag("en-CH-u-cf-account"), -100, "CHF-100.00"}, + {Locale.forLanguageTag("en-CH-u-cf-bogus"), -100, "CHF-100.00"}, + + // Region override + {Locale.forLanguageTag("en-US-u-rg-CHZZZZ"), -100, "CHF-100.00"}, + {Locale.forLanguageTag("en-US-u-rg-CHZZZZ-cf-standard"), -100, "CHF-100.00"}, + {Locale.forLanguageTag("en-US-u-rg-CHZZZZ-cf-account"), -100, "CHF-100.00"}, + {Locale.forLanguageTag("en-US-u-rg-CHZZZZ-cf-bogus"), -100, "CHF-100.00"}, + }; + } + + @Test(dataProvider="getInstanceData") + public void test_getInstance(Locale locale, int amount, String expected) { + assertEquals(NumberFormat.getCurrencyInstance(locale).format(amount), expected); + } +}