Print this page
rev 5615 : 6336885: RFE: Locale Data Deployment Enhancements
4609153: Provide locale data for Indic locales
5104387: Support for gl_ES locale (galician language)
6337471: desktop/system locale preferences support
7056139: (cal) SPI support for locale-dependent Calendar parameters
7058206: Provide CalendarData SPI for week params and display field value names
7073852: Support multiple scripts for digits and decimal symbols per locale
7079560: [Fmt-Da] Context dependent month names support in SimpleDateFormat
7171324: getAvailableLocales() of locale sensitive services should return the actual availability of locales
7151414: (cal) Support calendar type identification
7168528: LocaleServiceProvider needs to be aware of Locale extensions
7171372: (cal) locale's default Calendar should be created if unknown calendar is specified
Summary: JEP 127: Improve Locale Data Packaging and Adopt Unicode CLDR Data (part 1 w/o Jigsaw. by Naoto Sato and Masayoshi Okutsu)

Split Close
Expand all
Collapse all
          --- old/test/java/util/PluggableLocale/GenericTest.java
          +++ new/test/java/util/PluggableLocale/GenericTest.java
   1    1  /*
   2      - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
        2 + * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
   3    3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4    4   *
   5    5   * This code is free software; you can redistribute it and/or modify it
   6    6   * under the terms of the GNU General Public License version 2 only, as
   7    7   * published by the Free Software Foundation.
   8    8   *
   9    9   * This code is distributed in the hope that it will be useful, but WITHOUT
  10   10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11   11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12   12   * version 2 for more details (a copy is included in the LICENSE file that
↓ open down ↓ 6 lines elided ↑ open up ↑
  19   19   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20   20   * or visit www.oracle.com if you need additional information or have any
  21   21   * questions.
  22   22   */
  23   23  /*
  24   24   *
  25   25   */
  26   26  
  27   27  import java.text.*;
  28   28  import java.util.*;
  29      -import sun.util.resources.*;
       29 +import sun.util.locale.provider.*;
  30   30  
  31   31  public class GenericTest {
  32   32  
  33   33      // test providers
  34   34      com.foo.BreakIteratorProviderImpl breakIP = new com.foo.BreakIteratorProviderImpl();
  35   35      com.foo.CollatorProviderImpl collatorP = new com.foo.CollatorProviderImpl();
  36   36      com.foo.DateFormatProviderImpl dateFP = new com.foo.DateFormatProviderImpl();
  37   37      com.foo.DateFormatSymbolsProviderImpl dateFSP = new com.foo.DateFormatSymbolsProviderImpl();
  38   38      com.foo.DecimalFormatSymbolsProviderImpl decimalFSP = new com.foo.DecimalFormatSymbolsProviderImpl();
  39   39      com.foo.NumberFormatProviderImpl numberFP = new com.foo.NumberFormatProviderImpl();
  40   40      com.bar.CurrencyNameProviderImpl currencyNP = new com.bar.CurrencyNameProviderImpl();
  41   41      com.bar.LocaleNameProviderImpl localeNP = new com.bar.LocaleNameProviderImpl();
  42   42      com.bar.TimeZoneNameProviderImpl tzNP = new com.bar.TimeZoneNameProviderImpl();
       43 +    com.bar.CalendarDataProviderImpl calDataP = new com.bar.CalendarDataProviderImpl();
  43   44  
  44   45      public static void main(String[] s) {
  45   46          new GenericTest();
  46   47      }
  47   48  
  48   49      GenericTest() {
  49   50          availableLocalesTest();
  50   51          localeFallbackTest();
  51   52      }
  52   53  
  53   54      /**
  54   55       * Make sure that all the locales are available from the existing providers
  55   56       */
  56   57      void availableLocalesTest() {
  57   58          // Check that Locale.getAvailableLocales() returns the union of the JRE supported
  58   59          // locales and providers' locales
  59   60          HashSet<Locale> result =
  60      -            new HashSet<Locale>(Arrays.asList(Locale.getAvailableLocales()));
       61 +            new HashSet<>(Arrays.asList(Locale.getAvailableLocales()));
  61   62          HashSet<Locale> expected =
  62      -            new HashSet<Locale>(Arrays.asList(LocaleData.getAvailableLocales()));
       63 +            new HashSet<>(Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales()));
  63   64          expected.addAll(Arrays.asList(breakIP.getAvailableLocales()));
  64   65          expected.addAll(Arrays.asList(collatorP.getAvailableLocales()));
  65   66          expected.addAll(Arrays.asList(dateFP.getAvailableLocales()));
  66   67          expected.addAll(Arrays.asList(dateFSP.getAvailableLocales()));
  67   68          expected.addAll(Arrays.asList(decimalFSP.getAvailableLocales()));
  68   69          expected.addAll(Arrays.asList(numberFP.getAvailableLocales()));
  69   70          expected.addAll(Arrays.asList(currencyNP.getAvailableLocales()));
  70   71          expected.addAll(Arrays.asList(localeNP.getAvailableLocales()));
  71   72          expected.addAll(Arrays.asList(tzNP.getAvailableLocales()));
       73 +        expected.addAll(Arrays.asList(calDataP.getAvailableLocales()));
       74 +        expected.remove(Locale.ROOT);
  72   75          if (!result.equals(expected)) {
  73      -            throw new RuntimeException("Locale.getAvailableLocales() does not return the union of locales");
       76 +            throw new RuntimeException("Locale.getAvailableLocales() does not return the union of locales: diff="
       77 +                                       + getDiff(result, expected));
  74   78          }
  75   79      }
  76   80  
  77   81      /**
  78   82       * test with "xx_YY_ZZ", which is an example locale not contained
  79   83       * in Locale.getAvailableLocales().  Fallback tests for supported locales
  80   84       * are done in each xxxProviderTest test cases.
  81   85       */
  82   86      void localeFallbackTest() {
  83   87          Locale xx = new Locale("xx");
  84   88          Locale dispLocale = new Locale ("xx", "YY", "ZZ");
  85   89  
  86   90          String xxname = xx.getDisplayLanguage(xx);
  87   91          String expected = localeNP.getDisplayLanguage(xx.getLanguage(), dispLocale);
  88   92          if (!xxname.equals(expected)) {
  89   93              throw new RuntimeException("Locale fallback did not perform correctly. got: "+xxname+" expected: "+expected);
  90   94          }
  91   95      }
       96 +
       97 +    private static String getDiff(Set set1, Set set2) {
       98 +        Set s1 = (Set)((HashSet)set1).clone();
       99 +        s1.removeAll(set2);
      100 +
      101 +        Set s2 = (Set)((HashSet)set2).clone();
      102 +        s2.removeAll(set1);
      103 +        s2.addAll(s1);
      104 +        return s2.toString();
      105 +    }
  92  106  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX