test/java/util/PluggableLocale/DateFormatProviderTest.java

Print this page
rev 6057 : imported patch 8001205.8001562


  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 DateFormatProviderTest extends ProviderTest {
  33 
  34     com.foo.DateFormatProviderImpl dfp = new com.foo.DateFormatProviderImpl();
  35     List<Locale> availloc = Arrays.asList(DateFormat.getAvailableLocales());
  36     List<Locale> providerloc = Arrays.asList(dfp.getAvailableLocales());

  37     List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getDateFormatProvider().getAvailableLocales());
  38 
  39     public static void main(String[] s) {
  40         new DateFormatProviderTest();
  41     }
  42 
  43     DateFormatProviderTest() {

  44         objectValidityTest();
  45         extendedVariantTest();
  46         messageFormatTest();
  47     }
  48 











  49     void objectValidityTest() {
  50 
  51         for (Locale target: availloc) {
  52             // Get the key for the date/time patterns which is
  53             // specific to each calendar system.
  54             Calendar cal = Calendar.getInstance(target);
  55             String dkey = "DatePatterns";
  56             String tkey = "TimePatterns";
  57             String dtkey = "DateTimePatterns";
  58             switch (cal.getCalendarType()) {
  59                 case "java.util.JapaneseImperialCalendar":
  60                     dkey = "japanese"+ "." + dkey;
  61                     tkey = "japanese"+ "." + tkey;
  62                     dtkey = "japanese"+ "." + dtkey;
  63                     break;
  64                 case "sun.util.BuddhistCalendar":
  65                     dkey = "buddhist"+ "." + dkey;
  66                     tkey = "buddhist"+ "." + tkey;
  67                     dtkey = "buddhist"+ "." + dtkey;
  68                     break;




  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 DateFormatProviderTest extends ProviderTest {
  33 
  34     com.foo.DateFormatProviderImpl dfp = new com.foo.DateFormatProviderImpl();
  35     List<Locale> availloc = Arrays.asList(DateFormat.getAvailableLocales());
  36     List<Locale> providerloc = Arrays.asList(dfp.getAvailableLocales());
  37     List<Locale> jreloc = Arrays.asList(LocaleProviderAdapter.forJRE().getAvailableLocales());
  38     List<Locale> jreimplloc = Arrays.asList(LocaleProviderAdapter.forJRE().getDateFormatProvider().getAvailableLocales());
  39 
  40     public static void main(String[] s) {
  41         new DateFormatProviderTest();
  42     }
  43 
  44     DateFormatProviderTest() {
  45         availableLocalesTest();
  46         objectValidityTest();
  47         extendedVariantTest();
  48         messageFormatTest();
  49     }
  50 
  51     void availableLocalesTest() {
  52         Set<Locale> localesFromAPI = new HashSet<Locale>(availloc);
  53         Set<Locale> localesExpected = new HashSet<Locale>(jreloc);
  54         localesExpected.addAll(providerloc);
  55         if (localesFromAPI.equals(localesExpected)) {
  56             System.out.println("availableLocalesTest passed.");
  57         } else {
  58             throw new RuntimeException("availableLocalesTest failed");
  59         }
  60     }
  61 
  62     void objectValidityTest() {
  63 
  64         for (Locale target: availloc) {
  65             // Get the key for the date/time patterns which is
  66             // specific to each calendar system.
  67             Calendar cal = Calendar.getInstance(target);
  68             String dkey = "DatePatterns";
  69             String tkey = "TimePatterns";
  70             String dtkey = "DateTimePatterns";
  71             switch (cal.getCalendarType()) {
  72                 case "java.util.JapaneseImperialCalendar":
  73                     dkey = "japanese"+ "." + dkey;
  74                     tkey = "japanese"+ "." + tkey;
  75                     dtkey = "japanese"+ "." + dtkey;
  76                     break;
  77                 case "sun.util.BuddhistCalendar":
  78                     dkey = "buddhist"+ "." + dkey;
  79                     tkey = "buddhist"+ "." + tkey;
  80                     dtkey = "buddhist"+ "." + dtkey;
  81                     break;