Path: blob/master/test/jdk/java/util/Locale/bcp47u/CurrencyTests.java
41153 views
/*1* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24*25* @test26* @bug 817684127* @summary Tests Currency class instantiates correctly with Unicode28* extensions29* @modules jdk.localedata30* @run testng/othervm CurrencyTests31*/3233import static org.testng.Assert.assertEquals;3435import java.util.Currency;36import java.util.Locale;3738import org.testng.annotations.DataProvider;39import org.testng.annotations.Test;4041/**42* Test Currency with BCP47 U extensions43*/44@Test45public class CurrencyTests {46private static final Currency USD = Currency.getInstance("USD");47private static final Currency CAD = Currency.getInstance("CAD");48private static final Currency JPY = Currency.getInstance("JPY");4950@DataProvider(name="getInstanceData")51Object[][] getInstanceData() {52return new Object[][] {53// Locale, Expected Currency54// "cu"55{Locale.forLanguageTag("en-US-u-cu-jpy"), JPY},56{Locale.forLanguageTag("ja-JP-u-cu-usd"), USD},57{Locale.forLanguageTag("en-US-u-cu-foobar"), USD},58{Locale.forLanguageTag("en-US-u-cu-zzz"), USD},5960// "rg"61{Locale.forLanguageTag("en-US-u-rg-jpzzzz"), JPY},62{Locale.forLanguageTag("ja-JP-u-rg-uszzzz"), USD},63{Locale.forLanguageTag("ja-JP-u-rg-001zzzz"), JPY},64{Locale.forLanguageTag("en-US-u-rg-jpz"), USD},6566// "cu" and "rg". "cu" should win67{Locale.forLanguageTag("en-CA-u-cu-jpy-rg-uszzzz"), JPY},6869// invaid "cu" and valid "rg". "rg" should win70{Locale.forLanguageTag("en-CA-u-cu-jpyy-rg-uszzzz"), USD},71{Locale.forLanguageTag("en-CA-u-cu-zzz-rg-uszzzz"), USD},7273// invaid "cu" and invalid "rg". both should be ignored74{Locale.forLanguageTag("en-CA-u-cu-jpyy-rg-jpzz"), CAD},75};76}7778@DataProvider(name="getSymbolData")79Object[][] getSymbolData() {80return new Object[][] {81// Currency, DisplayLocale, expected Symbol82{USD, Locale.forLanguageTag("en-US-u-rg-jpzzzz"), "$"},83{USD, Locale.forLanguageTag("en-US-u-rg-cazzzz"), "US$"},84{USD, Locale.forLanguageTag("en-CA-u-rg-uszzzz"), "$"},8586{CAD, Locale.forLanguageTag("en-US-u-rg-jpzzzz"), "CA$"},87{CAD, Locale.forLanguageTag("en-US-u-rg-cazzzz"), "$"},88{CAD, Locale.forLanguageTag("en-CA-u-rg-uszzzz"), "CA$"},8990{JPY, Locale.forLanguageTag("ja-JP-u-rg-uszzzz"), "\uffe5"},91{JPY, Locale.forLanguageTag("en-US-u-rg-jpzzzz"), "\u00a5"},92{JPY, Locale.forLanguageTag("ko-KR-u-rg-jpzzzz"), "JP\u00a5"},93};94}9596@Test(dataProvider="getInstanceData")97public void test_getInstance(Locale locale, Currency currencyExpected) {98assertEquals(Currency.getInstance(locale), currencyExpected);99}100101@Test(dataProvider="getSymbolData")102public void test_getSymbol(Currency c, Locale locale, String expected) {103assertEquals(c.getSymbol(locale), expected);104}105}106107108