jdk/test/java/util/PluggableLocale/CurrencyNameProviderTest.java
changeset 14331 d3411e624053
parent 14185 916ec0a4d039
child 15260 7af2d7a87806
equal deleted inserted replaced
14330:e4cb78065603 14331:d3411e624053
    46         test2();
    46         test2();
    47     }
    47     }
    48 
    48 
    49     void test1() {
    49     void test1() {
    50         com.bar.CurrencyNameProviderImpl cnp = new com.bar.CurrencyNameProviderImpl();
    50         com.bar.CurrencyNameProviderImpl cnp = new com.bar.CurrencyNameProviderImpl();
       
    51         com.bar.CurrencyNameProviderImpl2 cnp2 = new com.bar.CurrencyNameProviderImpl2();
    51         Locale[] availloc = Locale.getAvailableLocales();
    52         Locale[] availloc = Locale.getAvailableLocales();
    52         Locale[] testloc = availloc.clone();
    53         Locale[] testloc = availloc.clone();
    53         List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCurrencyNameProvider().getAvailableLocales());
    54         List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCurrencyNameProvider().getAvailableLocales());
    54         List<Locale> providerloc = Arrays.asList(cnp.getAvailableLocales());
    55         List<Locale> providerloc = new ArrayList<Locale>();
       
    56         providerloc.addAll(Arrays.asList(cnp.getAvailableLocales()));
       
    57         providerloc.addAll(Arrays.asList(cnp2.getAvailableLocales()));
    55 
    58 
    56         for (Locale target: availloc) {
    59         for (Locale target: availloc) {
    57             // pure JRE implementation
    60             // pure JRE implementation
    58             OpenListResourceBundle rb = (OpenListResourceBundle)LocaleProviderAdapter.forJRE().getLocaleData().getCurrencyNames(target);
    61             OpenListResourceBundle rb = (OpenListResourceBundle)LocaleProviderAdapter.forJRE().getLocaleData().getCurrencyNames(target);
    59             boolean jreSupportsTarget = jreimplloc.contains(target);
    62             boolean jreSupportsTarget = jreimplloc.contains(target);
    77 
    80 
    78                 // provider's name (if any)
    81                 // provider's name (if any)
    79                 String providerscurrency = null;
    82                 String providerscurrency = null;
    80                 String providersname = null;
    83                 String providersname = null;
    81                 if (providerloc.contains(target)) {
    84                 if (providerloc.contains(target)) {
       
    85                     if (cnp.isSupportedLocale(target)) {
    82                     providerscurrency = cnp.getSymbol(c.getCurrencyCode(), target);
    86                     providerscurrency = cnp.getSymbol(c.getCurrencyCode(), target);
    83                     providersname = cnp.getDisplayName(c.getCurrencyCode(), target);
    87                     providersname = cnp.getDisplayName(c.getCurrencyCode(), target);
       
    88                     } else {
       
    89                         providerscurrency = cnp2.getSymbol(c.getCurrencyCode(), target);
       
    90                         providersname = cnp2.getDisplayName(c.getCurrencyCode(), target);
       
    91                     }
    84                 }
    92                 }
    85 
    93 
    86                 // JRE's name
    94                 // JRE's name
    87                 String jrescurrency = null;
    95                 String jrescurrency = null;
    88                 String jresname = null;
    96                 String jresname = null;
   107 
   115 
   108 
   116 
   109     final String pattern = "###,###\u00A4";
   117     final String pattern = "###,###\u00A4";
   110     final String YEN_IN_OSAKA = "100,000\u5186\u3084\u3002";
   118     final String YEN_IN_OSAKA = "100,000\u5186\u3084\u3002";
   111     final String YEN_IN_KYOTO = "100,000\u5186\u3069\u3059\u3002";
   119     final String YEN_IN_KYOTO = "100,000\u5186\u3069\u3059\u3002";
       
   120     final String YEN_IN_TOKYO= "100,000JPY-tokyo";
   112     final Locale OSAKA = new Locale("ja", "JP", "osaka");
   121     final Locale OSAKA = new Locale("ja", "JP", "osaka");
   113     final Locale KYOTO = new Locale("ja", "JP", "kyoto");
   122     final Locale KYOTO = new Locale("ja", "JP", "kyoto");
       
   123     final Locale TOKYO = new Locale("ja", "JP", "tokyo");
   114     Integer i = new Integer(100000);
   124     Integer i = new Integer(100000);
   115     String formatted;
   125     String formatted;
   116     DecimalFormat df;
   126     DecimalFormat df;
   117 
   127 
   118     void test2() {
   128     void test2() {
       
   129         Locale defloc = Locale.getDefault();
       
   130 
   119         try {
   131         try {
   120             df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(OSAKA));
   132             df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(OSAKA));
   121             System.out.println(formatted = df.format(i));
   133             System.out.println(formatted = df.format(i));
   122             if(!formatted.equals(YEN_IN_OSAKA)) {
   134             if(!formatted.equals(YEN_IN_OSAKA)) {
   123                 throw new RuntimeException("formatted zone names mismatch. " +
   135                 throw new RuntimeException("formatted currency names mismatch. " +
   124                     "Should match with " + YEN_IN_OSAKA);
   136                     "Should match with " + YEN_IN_OSAKA);
   125             }
   137             }
   126 
   138 
   127             df.parse(YEN_IN_OSAKA);
   139             df.parse(YEN_IN_OSAKA);
   128 
   140 
   129             Locale.setDefault(KYOTO);
   141             Locale.setDefault(KYOTO);
   130             df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance());
   142             df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance());
   131             System.out.println(formatted = df.format(i));
   143             System.out.println(formatted = df.format(i));
   132             if(!formatted.equals(YEN_IN_KYOTO)) {
   144             if(!formatted.equals(YEN_IN_KYOTO)) {
   133                 throw new RuntimeException("formatted zone names mismatch. " +
   145                 throw new RuntimeException("formatted currency names mismatch. " +
   134                     "Should match with " + YEN_IN_KYOTO);
   146                     "Should match with " + YEN_IN_KYOTO);
   135             }
   147             }
   136 
   148 
   137             df.parse(YEN_IN_KYOTO);
   149             df.parse(YEN_IN_KYOTO);
       
   150 
       
   151             Locale.setDefault(TOKYO);
       
   152             df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance());
       
   153             System.out.println(formatted = df.format(i));
       
   154             if(!formatted.equals(YEN_IN_TOKYO)) {
       
   155                 throw new RuntimeException("formatted currency names mismatch. " +
       
   156                     "Should match with " + YEN_IN_TOKYO);
       
   157             }
       
   158 
       
   159             df.parse(YEN_IN_TOKYO);
   138         } catch (ParseException pe) {
   160         } catch (ParseException pe) {
   139             throw new RuntimeException("parse error occured" + pe);
   161             throw new RuntimeException("parse error occured" + pe);
       
   162         } finally {
       
   163             Locale.setDefault(defloc);
   140         }
   164         }
   141     }
   165     }
   142 }
   166 }