Print this page
rev 5974 : imported patch 8000997

Split Close
Expand all
Collapse all
          --- old/test/java/util/PluggableLocale/CurrencyNameProviderTest.java
          +++ new/test/java/util/PluggableLocale/CurrencyNameProviderTest.java
↓ open down ↓ 40 lines elided ↑ open up ↑
  41   41          }
  42   42      }
  43   43  
  44   44      CurrencyNameProviderTest() {
  45   45          test1();
  46   46          test2();
  47   47      }
  48   48  
  49   49      void test1() {
  50   50          com.bar.CurrencyNameProviderImpl cnp = new com.bar.CurrencyNameProviderImpl();
       51 +        com.bar.CurrencyNameProviderImpl2 cnp2 = new com.bar.CurrencyNameProviderImpl2();
  51   52          Locale[] availloc = Locale.getAvailableLocales();
  52   53          Locale[] testloc = availloc.clone();
  53   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   59          for (Locale target: availloc) {
  57   60              // pure JRE implementation
  58   61              OpenListResourceBundle rb = (OpenListResourceBundle)LocaleProviderAdapter.forJRE().getLocaleData().getCurrencyNames(target);
  59   62              boolean jreSupportsTarget = jreimplloc.contains(target);
  60   63  
  61   64              for (Locale test: testloc) {
  62   65                  // get a Currency instance
  63   66                  Currency c = null;
  64   67                  try {
↓ open down ↓ 7 lines elided ↑ open up ↑
  72   75                  // the localized symbol for the target locale
  73   76                  String currencyresult = c.getSymbol(target);
  74   77  
  75   78                  // the localized name for the target locale
  76   79                  String nameresult = c.getDisplayName(target);
  77   80  
  78   81                  // provider's name (if any)
  79   82                  String providerscurrency = null;
  80   83                  String providersname = null;
  81   84                  if (providerloc.contains(target)) {
  82      -                    providerscurrency = cnp.getSymbol(c.getCurrencyCode(), target);
  83      -                    providersname = cnp.getDisplayName(c.getCurrencyCode(), target);
       85 +                    if (cnp.isSupportedLocale(target)) {
       86 +                        providerscurrency = cnp.getSymbol(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   94                  // JRE's name
  87   95                  String jrescurrency = null;
  88   96                  String jresname = null;
  89   97                  String key = c.getCurrencyCode();
  90   98                  String nameKey = key.toLowerCase(Locale.ROOT);
  91   99                  if (jreSupportsTarget) {
  92  100                      try {
  93  101                          jrescurrency = rb.getString(key);
↓ open down ↓ 8 lines elided ↑ open up ↑
 102  110                  checkValidity(target, jresname, providersname, nameresult,
 103  111                                jreSupportsTarget && jresname != null);
 104  112              }
 105  113          }
 106  114      }
 107  115  
 108  116  
 109  117      final String pattern = "###,###\u00A4";
 110  118      final String YEN_IN_OSAKA = "100,000\u5186\u3084\u3002";
 111  119      final String YEN_IN_KYOTO = "100,000\u5186\u3069\u3059\u3002";
      120 +    final String YEN_IN_TOKYO= "100,000JPY-tokyo";
 112  121      final Locale OSAKA = new Locale("ja", "JP", "osaka");
 113  122      final Locale KYOTO = new Locale("ja", "JP", "kyoto");
      123 +    final Locale TOKYO = new Locale("ja", "JP", "tokyo");
 114  124      Integer i = new Integer(100000);
 115  125      String formatted;
 116  126      DecimalFormat df;
 117  127  
 118  128      void test2() {
      129 +        Locale defloc = Locale.getDefault();
      130 +
 119  131          try {
 120  132              df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(OSAKA));
 121  133              System.out.println(formatted = df.format(i));
 122  134              if(!formatted.equals(YEN_IN_OSAKA)) {
 123      -                throw new RuntimeException("formatted zone names mismatch. " +
      135 +                throw new RuntimeException("formatted currency names mismatch. " +
 124  136                      "Should match with " + YEN_IN_OSAKA);
 125  137              }
 126  138  
 127  139              df.parse(YEN_IN_OSAKA);
 128  140  
 129  141              Locale.setDefault(KYOTO);
 130  142              df = new DecimalFormat(pattern, DecimalFormatSymbols.getInstance());
 131  143              System.out.println(formatted = df.format(i));
 132  144              if(!formatted.equals(YEN_IN_KYOTO)) {
 133      -                throw new RuntimeException("formatted zone names mismatch. " +
      145 +                throw new RuntimeException("formatted currency names mismatch. " +
 134  146                      "Should match with " + YEN_IN_KYOTO);
 135  147              }
 136  148  
 137  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  160          } catch (ParseException pe) {
 139  161              throw new RuntimeException("parse error occured" + pe);
      162 +        } finally {
      163 +            Locale.setDefault(defloc);
 140  164          }
 141  165      }
 142  166  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX