@Test(dataProvider = "calendarNameAndType")
 public void test_getters(String chronoId, String calendarSystemType) {
   Chronology chrono = Chronology.of(chronoId);
   assertNotNull(chrono, "Required calendar not found by ID: " + chronoId);
   assertEquals(chrono.getId(), chronoId);
   assertEquals(chrono.getCalendarType(), calendarSystemType);
 }
 @Test
 public void test_JapaneseChronology_dateYearDay() {
   Chronology chrono = Chronology.of("Japanese");
   ChronoLocalDate date1 = chrono.dateYearDay(JapaneseEra.HEISEI, 8, 60);
   ChronoLocalDate date2 = chrono.date(JapaneseEra.HEISEI, 8, 2, 29);
   assertEquals(date1, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
   assertEquals(date2, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
 }
 @Test
 public void test_MinguoChronology_dateYearDay() {
   Chronology chrono = Chronology.of("Minguo");
   ChronoLocalDate date1 = chrono.dateYearDay(MinguoEra.ROC, 5, 60);
   ChronoLocalDate date2 = chrono.date(MinguoEra.ROC, 5, 2, 29);
   assertEquals(date1, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
   assertEquals(date2, MinguoChronology.INSTANCE.dateYearDay(MinguoEra.ROC, 5, 60));
 }
 @Test(dataProvider = "calendarNameAndType")
 public void test_dateEpochDay(String name, String alias) {
   Chronology chrono = Chronology.of(name);
   ChronoLocalDate date = chrono.dateNow();
   long epochDay = date.getLong(ChronoField.EPOCH_DAY);
   ChronoLocalDate test = chrono.dateEpochDay(epochDay);
   assertEquals(test, date);
 }
 // -----------------------------------------------------------------------
 // dateYearDay() and date()
 // -----------------------------------------------------------------------
 @Test
 public void test_HijrahChronology_dateYearDay() {
   Chronology chrono = Chronology.of("Hijrah");
   ChronoLocalDate date1 = chrono.dateYearDay(HijrahEra.AH, 1434, 178);
   ChronoLocalDate date2 = chrono.date(HijrahEra.AH, 1434, 7, 1);
   assertEquals(date1, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
   assertEquals(date2, HijrahChronology.INSTANCE.dateYearDay(HijrahEra.AH, 1434, 178));
 }
 @Test
 public void test_IsoChronology_dateYearDay() {
   Chronology chrono = Chronology.of("ISO");
   ChronoLocalDate date1 = chrono.dateYearDay(IsoEra.CE, 5, 60);
   ChronoLocalDate date2 = chrono.date(IsoEra.CE, 5, 3, 1);
   assertEquals(date1, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60));
   assertEquals(date2, IsoChronology.INSTANCE.dateYearDay(IsoEra.CE, 5, 60));
 }
 @Test
 public void test_ThaiBuddhistChronology_dateYearDay() {
   Chronology chrono = Chronology.of("ThaiBuddhist");
   ChronoLocalDate date1 = chrono.dateYearDay(ThaiBuddhistEra.BE, 2459, 60);
   ChronoLocalDate date2 = chrono.date(ThaiBuddhistEra.BE, 2459, 2, 29);
   assertEquals(date1, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
   assertEquals(date2, ThaiBuddhistChronology.INSTANCE.dateYearDay(ThaiBuddhistEra.BE, 2459, 60));
 }
 // -----------------------------------------------------------------------
 // Chronology.of(String)
 // -----------------------------------------------------------------------
 @Test
 public void test_chrono_byName() {
   Chronology c = JapaneseChronology.INSTANCE;
   Chronology test = Chronology.of("Japanese");
   Assert.assertNotNull(test, "The Japanese calendar could not be found byName");
   Assert.assertEquals(test.getId(), "Japanese", "ID mismatch");
   Assert.assertEquals(test.getCalendarType(), "japanese", "Type mismatch");
   Assert.assertEquals(test, c);
 }
 @Test(dataProvider = "calendarNameAndType")
 public void test_required_calendars(String chronoId, String calendarSystemType) {
   Chronology chrono = Chronology.of(chronoId);
   assertNotNull(chrono, "Required calendar not found by ID: " + chronoId);
   chrono = Chronology.of(calendarSystemType);
   assertNotNull(chrono, "Required calendar not found by type: " + chronoId);
   Set<Chronology> cals = Chronology.getAvailableChronologies();
   assertTrue(cals.contains(chrono), "Required calendar not found in set of available calendars");
 }
 /** Compute the number of days from the Epoch and compute the date from the number of days. */
 @Test(dataProvider = "calendarNameAndType")
 public void test_epoch(String name, String alias) {
   Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
   ChronoLocalDate date1 = chrono.dateNow();
   long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
   ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
   assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
   long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
   assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
 }
  @Test
  public void test_JapaneseChronology_dateNow() {
    ZoneId zoneId_paris = ZoneId.of("Europe/Paris");
    Clock clock = Clock.system(zoneId_paris);

    Chronology chrono = Chronology.of("Japanese");
    assertEquals(chrono.dateNow(), JapaneseChronology.INSTANCE.dateNow());
    assertEquals(chrono.dateNow(zoneId_paris), JapaneseChronology.INSTANCE.dateNow(zoneId_paris));
    assertEquals(chrono.dateNow(clock), JapaneseChronology.INSTANCE.dateNow(clock));
  }
 /**
  * Test lookup by calendarType of each chronology. Verify that the calendar can be found by {@link
  * java.time.chrono.Chronology#ofLocale}.
  */
 @Test
 public void test_ofLocaleByType() {
   // Test that all available chronologies can be successfully found using ofLocale
   Set<Chronology> chronos = Chronology.getAvailableChronologies();
   for (Chronology chrono : chronos) {
     Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
     builder.setUnicodeLocaleKeyword("ca", chrono.getCalendarType());
     Locale locale = builder.build();
     assertEquals(Chronology.ofLocale(locale), chrono, "Lookup by type");
   }
 }
 @Test
 public void test_calendar_list() {
   Set<Chronology> chronos = Chronology.getAvailableChronologies();
   assertNotNull(chronos, "Required list of calendars must be non-null");
   for (Chronology chrono : chronos) {
     Chronology lookup = Chronology.of(chrono.getId());
     assertNotNull(lookup, "Required calendar not found: " + chrono);
   }
   assertEquals(
       chronos.size() >= data_of_calendars().length,
       true,
       "Chronology.getAvailableChronologies().size = "
           + chronos.size()
           + ", expected >= "
           + data_of_calendars().length);
 }
Exemple #14
0
 /**
  * Calculates the range of months based on the temporal.
  *
  * @param temporal the temporal, not null
  * @return the month range, negative if not fixed range
  */
 private long monthRange(Temporal temporal) {
   ValueRange startRange = Chronology.from(temporal).range(MONTH_OF_YEAR);
   if (startRange.isFixed() && startRange.isIntValue()) {
     return startRange.getMaximum() - startRange.getMinimum() + 1;
   }
   return -1;
 }
 @Test(dataProvider = "calendarsystemtype")
 public void test_lookupLocale(Chronology chrono, String calendarType) {
   Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
   builder.setUnicodeLocaleKeyword("ca", calendarType);
   Locale locale = builder.build();
   assertEquals(Chronology.ofLocale(locale), chrono);
 }
  @Test(expectedExceptions = DateTimeException.class)
  public void test_lookupLocale() {
    Locale.Builder builder = new Locale.Builder().setLanguage("en").setRegion("CA");
    builder.setUnicodeLocaleKeyword("ca", "xxx");

    Locale locale = builder.build();
    Chronology.ofLocale(locale);
  }
 // -----------------------------------------------------------------------
 // serialization; serialize and check each calendar system
 // -----------------------------------------------------------------------
 @Test(dataProvider = "calendarNameAndType")
 public void test_chronoSerializationSingleton(String id, String _calendarType) throws Exception {
   Chronology original = Chronology.of(id);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   ObjectOutputStream out = new ObjectOutputStream(baos);
   out.writeObject(original);
   out.close();
   ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
   ObjectInputStream in = new ObjectInputStream(bais);
   Chronology ser = (Chronology) in.readObject();
   assertEquals(ser, original, "Deserialized Chronology is not correct");
 }
 @Test
 public void test_chrono_byLocale_iso() {
   Assert.assertEquals(Chronology.ofLocale(new Locale("ja", "JP")).getId(), "ISO");
   Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP")).getId(), "ISO");
   Assert.assertEquals(Chronology.ofLocale(Locale.forLanguageTag("ja-JP-JP")).getId(), "ISO");
 }
 @Test
 public void test_chrono_byLocale_oldJP_variant() {
   Chronology test = Chronology.ofLocale(new Locale("ja", "JP", "JP"));
   Assert.assertEquals(test.getId(), "Japanese");
   Assert.assertEquals(test, JapaneseChronology.INSTANCE);
 }
 @Test
 public void test_chrono_byLocale_oldJP_noVariant() {
   Chronology test = Chronology.ofLocale(new Locale("ja", "JP"));
   Assert.assertEquals(test.getId(), "ISO");
   Assert.assertEquals(test, IsoChronology.INSTANCE);
 }
 @Test
 public void test_chrono_byLocale_fullTag_japaneseCalendarFromElsewhere() {
   Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-japanese"));
   Assert.assertEquals(test.getId(), "Japanese");
   Assert.assertEquals(test, JapaneseChronology.INSTANCE);
 }
 @Test(expectedExceptions = DateTimeException.class)
 public void test_noChrono() {
   Chronology chrono = Chronology.of("FooFoo");
 }
 @Test(dataProvider = "calendarDisplayName")
 public void test_getDisplayName(String chronoId, String calendarDisplayName) {
   Chronology chrono = Chronology.of(chronoId);
   assertEquals(chrono.getDisplayName(TextStyle.FULL, Locale.ENGLISH), calendarDisplayName);
 }
 @Test(dataProvider = "calendarsystemtype")
 public void test_getCalendarType(Chronology chrono, String calendarType) {
   String type = calendarType;
   assertEquals(chrono.getCalendarType(), type);
 }