Exemplo n.º 1
0
 @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);
 }
Exemplo n.º 2
0
 @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));
 }
Exemplo n.º 3
0
 @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));
 }
Exemplo n.º 4
0
 @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);
 }
Exemplo n.º 5
0
 // -----------------------------------------------------------------------
 // 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));
 }
Exemplo n.º 6
0
 @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));
 }
Exemplo n.º 7
0
 @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));
 }
Exemplo n.º 8
0
 // -----------------------------------------------------------------------
 // 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);
 }
Exemplo n.º 9
0
 @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");
 }
Exemplo n.º 10
0
 /** 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);
 }
Exemplo n.º 11
0
  @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));
  }
Exemplo n.º 12
0
 /**
  * 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");
   }
 }
Exemplo n.º 13
0
 @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);
 }
Exemplo n.º 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;
 }
Exemplo n.º 15
0
 @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);
 }
Exemplo n.º 16
0
  @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);
  }
Exemplo n.º 17
0
 // -----------------------------------------------------------------------
 // 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");
 }
Exemplo n.º 18
0
 @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");
 }
Exemplo n.º 19
0
 @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);
 }
Exemplo n.º 20
0
 @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);
 }
Exemplo n.º 21
0
 @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);
 }
Exemplo n.º 22
0
 @Test(expectedExceptions = DateTimeException.class)
 public void test_noChrono() {
   Chronology chrono = Chronology.of("FooFoo");
 }
Exemplo n.º 23
0
 @Test(dataProvider = "calendarDisplayName")
 public void test_getDisplayName(String chronoId, String calendarDisplayName) {
   Chronology chrono = Chronology.of(chronoId);
   assertEquals(chrono.getDisplayName(TextStyle.FULL, Locale.ENGLISH), calendarDisplayName);
 }
Exemplo n.º 24
0
 @Test(dataProvider = "calendarsystemtype")
 public void test_getCalendarType(Chronology chrono, String calendarType) {
   String type = calendarType;
   assertEquals(chrono.getCalendarType(), type);
 }