< prev index next >

test/jdk/java/util/PluggableLocale/CurrencyNameProviderTest.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */

  23 /*
  24  *









  25  */
  26 
  27 import java.text.*;
  28 import java.util.*;
  29 import sun.util.locale.provider.*;
  30 import sun.util.resources.*;












  31 
  32 public class CurrencyNameProviderTest extends ProviderTest {
  33 
  34     public static void main(String[] s) {
  35         Locale reservedLocale = Locale.getDefault();
  36         try {
  37             new CurrencyNameProviderTest();
  38         } finally {
  39             // restore the reserved locale
  40             Locale.setDefault(reservedLocale);
  41         }
  42     }
  43 
  44     CurrencyNameProviderTest() {
  45         test1();
  46         test2();
  47     }
  48 
  49     void test1() {
  50         com.bar.CurrencyNameProviderImpl cnp = new com.bar.CurrencyNameProviderImpl();
  51         com.bar.CurrencyNameProviderImpl2 cnp2 = new com.bar.CurrencyNameProviderImpl2();
  52         Locale[] availloc = Locale.getAvailableLocales();
  53         Locale[] testloc = availloc.clone();
  54         List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCurrencyNameProvider().getAvailableLocales());
  55         List<Locale> providerloc = new ArrayList<Locale>();
  56         providerloc.addAll(Arrays.asList(cnp.getAvailableLocales()));
  57         providerloc.addAll(Arrays.asList(cnp2.getAvailableLocales()));
  58 
  59         for (Locale target: availloc) {
  60             // pure JRE implementation
  61             OpenListResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getCurrencyNames(target);
  62             boolean jreSupportsTarget = jreimplloc.contains(target);
  63 
  64             for (Locale test: testloc) {
  65                 // get a Currency instance
  66                 Currency c = null;
  67                 try {
  68                     c = Currency.getInstance(test);
  69                 } catch (IllegalArgumentException iae) {}
  70 
  71                 if (c == null) {


   1 /*
   2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 4052440 7199750 8000997 8062588 8210406
  27  * @summary CurrencyNameProvider tests
  28  * @library providersrc/foobarutils
  29  *          providersrc/barprovider
  30  * @modules java.base/sun.util.locale.provider
  31  *          java.base/sun.util.resources
  32  * @build com.foobar.Utils
  33  *        com.bar.*
  34  * @run main/othervm -Djava.locale.providers=JRE,SPI CurrencyNameProviderTest
  35  */
  36 
  37 import java.text.DecimalFormat;
  38 import java.text.DecimalFormatSymbols;
  39 import java.text.ParseException;
  40 import java.util.ArrayList;
  41 import java.util.Arrays;
  42 import java.util.Currency;
  43 import java.util.List;
  44 import java.util.Locale;
  45 import java.util.MissingResourceException;
  46 
  47 import com.bar.CurrencyNameProviderImpl;
  48 import com.bar.CurrencyNameProviderImpl2;
  49 
  50 import sun.util.locale.provider.LocaleProviderAdapter;
  51 import sun.util.locale.provider.ResourceBundleBasedAdapter;
  52 import sun.util.resources.OpenListResourceBundle;
  53 
  54 public class CurrencyNameProviderTest extends ProviderTest {
  55 
  56     public static void main(String[] s) {
  57         Locale reservedLocale = Locale.getDefault();
  58         try {
  59             new CurrencyNameProviderTest();
  60         } finally {
  61             // restore the reserved locale
  62             Locale.setDefault(reservedLocale);
  63         }
  64     }
  65 
  66     CurrencyNameProviderTest() {
  67         test1();
  68         test2();
  69     }
  70 
  71     void test1() {
  72         CurrencyNameProviderImpl cnp = new CurrencyNameProviderImpl();
  73         CurrencyNameProviderImpl2 cnp2 = new CurrencyNameProviderImpl2();
  74         Locale[] availloc = Locale.getAvailableLocales();
  75         Locale[] testloc = availloc.clone();
  76         List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCurrencyNameProvider().getAvailableLocales());
  77         List<Locale> providerloc = new ArrayList<Locale>();
  78         providerloc.addAll(Arrays.asList(cnp.getAvailableLocales()));
  79         providerloc.addAll(Arrays.asList(cnp2.getAvailableLocales()));
  80 
  81         for (Locale target: availloc) {
  82             // pure JRE implementation
  83             OpenListResourceBundle rb = ((ResourceBundleBasedAdapter)LocaleProviderAdapter.forJRE()).getLocaleData().getCurrencyNames(target);
  84             boolean jreSupportsTarget = jreimplloc.contains(target);
  85 
  86             for (Locale test: testloc) {
  87                 // get a Currency instance
  88                 Currency c = null;
  89                 try {
  90                     c = Currency.getInstance(test);
  91                 } catch (IllegalArgumentException iae) {}
  92 
  93                 if (c == null) {


< prev index next >