test/java/util/PluggableLocale/CollatorProviderTest.java

Print this page
rev 6057 : imported patch 8001205.8001562


  31 
  32 public class CollatorProviderTest extends ProviderTest {
  33 
  34     com.foo.CollatorProviderImpl cp = new com.foo.CollatorProviderImpl();
  35     List<Locale> availloc = Arrays.asList(Collator.getAvailableLocales());
  36     List<Locale> providerloc = Arrays.asList(cp.getAvailableLocales());
  37     List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
  38     List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCollatorProvider().getAvailableLocales());
  39 
  40     public static void main(String[] s) {
  41         new CollatorProviderTest();
  42     }
  43 
  44     CollatorProviderTest() {
  45         availableLocalesTest();
  46         objectValidityTest();
  47     }
  48 
  49     void availableLocalesTest() {
  50         Set<Locale> localesFromAPI = new HashSet<Locale>(availloc);
  51         Set<Locale> localesExpected = new HashSet<Locale>(jreimplloc);
  52         localesExpected.remove(Locale.ROOT);
  53         localesExpected.addAll(providerloc);
  54         if (localesFromAPI.equals(localesExpected)) {
  55             System.out.println("availableLocalesTest passed.");
  56         } else {
  57             throw new RuntimeException("availableLocalesTest failed");
  58         }
  59     }
  60 
  61     void objectValidityTest() {
  62         Collator def = Collator.getInstance(new Locale(""));
  63         String defrules = ((RuleBasedCollator)def).getRules();
  64 
  65         for (Locale target: availloc) {
  66             // pure JRE implementation
  67             Set<Locale> jreimplloc = new HashSet<>();
  68             for (String tag : ((AvailableLanguageTags)LocaleProviderAdapter.forJRE().getCollatorProvider()).getAvailableLanguageTags()) {
  69                 jreimplloc.add(Locale.forLanguageTag(tag));
  70             }
  71             ResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getCollationData(target);
  72             boolean jreSupportsLocale = jreimplloc.contains(target);




  31 
  32 public class CollatorProviderTest extends ProviderTest {
  33 
  34     com.foo.CollatorProviderImpl cp = new com.foo.CollatorProviderImpl();
  35     List<Locale> availloc = Arrays.asList(Collator.getAvailableLocales());
  36     List<Locale> providerloc = Arrays.asList(cp.getAvailableLocales());
  37     List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
  38     List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getCollatorProvider().getAvailableLocales());
  39 
  40     public static void main(String[] s) {
  41         new CollatorProviderTest();
  42     }
  43 
  44     CollatorProviderTest() {
  45         availableLocalesTest();
  46         objectValidityTest();
  47     }
  48 
  49     void availableLocalesTest() {
  50         Set<Locale> localesFromAPI = new HashSet<Locale>(availloc);
  51         Set<Locale> localesExpected = new HashSet<Locale>(jreloc);

  52         localesExpected.addAll(providerloc);
  53         if (localesFromAPI.equals(localesExpected)) {
  54             System.out.println("availableLocalesTest passed.");
  55         } else {
  56             throw new RuntimeException("availableLocalesTest failed");
  57         }
  58     }
  59 
  60     void objectValidityTest() {
  61         Collator def = Collator.getInstance(new Locale(""));
  62         String defrules = ((RuleBasedCollator)def).getRules();
  63 
  64         for (Locale target: availloc) {
  65             // pure JRE implementation
  66             Set<Locale> jreimplloc = new HashSet<>();
  67             for (String tag : ((AvailableLanguageTags)LocaleProviderAdapter.forJRE().getCollatorProvider()).getAvailableLanguageTags()) {
  68                 jreimplloc.add(Locale.forLanguageTag(tag));
  69             }
  70             ResourceBundle rb = LocaleProviderAdapter.forJRE().getLocaleData().getCollationData(target);
  71             boolean jreSupportsLocale = jreimplloc.contains(target);