Ejemplo n.º 1
0
 private void assertMinguoDate(
     MinguoDate test, MinguoEra era, int year, MonthOfYear month, int day) throws Exception {
   assertEquals(test.getEra(), era);
   assertEquals(test.getYearOfEra(), year);
   assertEquals(test.getMonthOfYear(), month);
   assertEquals(test.getDayOfMonth(), day);
   assertEquals(test.isLeapYear(), isLeapYear(era.getValue(), year));
 }
Ejemplo n.º 2
0
 @Test
 public void testHashCode() throws Exception {
   MinguoDate a = MinguoDate.of(1, MonthOfYear.JANUARY, 1);
   MinguoDate b = MinguoDate.of(1, MonthOfYear.JANUARY, 1);
   assertEquals(a.hashCode(), a.hashCode());
   assertEquals(a.hashCode(), b.hashCode());
   assertEquals(b.hashCode(), b.hashCode());
 }
Ejemplo n.º 3
0
 @Test
 public void testEqualsNotEqualYear() throws Exception {
   MinguoDate a = MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth);
   MinguoDate b = MinguoDate.of(testYear + 1, testMonthOfYear, testDayOfMonth);
   assertEquals(a.equals(b), false);
   assertEquals(b.equals(a), false);
   assertEquals(a.equals(a), true);
   assertEquals(b.equals(b), true);
 }
Ejemplo n.º 4
0
 @Test
 public void testWithDayOfYearInvalidTooBig() throws Exception {
   try {
     testDate.withDayOfYear(367);
     fail();
   } catch (IllegalCalendarFieldValueException ex) {
     assertEquals(ex.getRule(), MinguoChronology.dayOfYearRule());
   }
 }
Ejemplo n.º 5
0
 @Test
 public void testWithYearInvalidTooBig() throws Exception {
   try {
     testDate.withYear(testEra, 10000);
     fail();
   } catch (IllegalCalendarFieldValueException ex) {
     assertEquals(ex.getRule(), MinguoChronology.yearOfEraRule());
   }
 }
Ejemplo n.º 6
0
 @Test
 public void testMinusWeeksOverflow() throws Exception {
   try {
     testDate.minusWeeks(Integer.MAX_VALUE);
     fail();
   } catch (IllegalCalendarFieldValueException ex) {
     assertEquals(ex.getRule(), MinguoChronology.yearOfEraRule());
   }
 }
Ejemplo n.º 7
0
 @Test
 public void test_factory_of_3_invalidDay() throws Exception {
   try {
     MinguoDate.of(testYear, testMonthOfYear, 40); // Invalid day of month.
     fail();
   } catch (IllegalCalendarFieldValueException ex) {
     assertEquals(ex.getRule(), MinguoChronology.dayOfMonthRule());
   }
 }
Ejemplo n.º 8
0
 @Test
 public void test_factory_of_3_invalidYear() throws Exception {
   try {
     MinguoDate.of(10000, testMonthOfYear, testDayOfMonth); // Invalid year.
     fail();
   } catch (IllegalCalendarFieldValueException ex) {
     assertEquals(ex.getRule(), MinguoChronology.yearOfEraRule());
   }
 }
Ejemplo n.º 9
0
 // -----------------------------------------------------------------------
 // getDayOfWeek()
 // -----------------------------------------------------------------------
 @Test
 public void testGetDayOfWeek() {
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 2).getDayOfWeek(), DayOfWeek.MONDAY);
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 3).getDayOfWeek(), DayOfWeek.TUESDAY);
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 4).getDayOfWeek(), DayOfWeek.WEDNESDAY);
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 5).getDayOfWeek(), DayOfWeek.THURSDAY);
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 6).getDayOfWeek(), DayOfWeek.FRIDAY);
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 7).getDayOfWeek(), DayOfWeek.SATURDAY);
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 8).getDayOfWeek(), DayOfWeek.SUNDAY);
   assertEquals(MinguoDate.of(testYear, testMonthOfYear, 9).getDayOfWeek(), DayOfWeek.MONDAY);
 }
Ejemplo n.º 10
0
 @Test(expectedExceptions = CalendricalException.class)
 public void testPlusYearsInvalidTooBig() {
   testDate.plusYears(9999);
 }
Ejemplo n.º 11
0
 @Test(expectedExceptions = NullPointerException.class)
 public void testIsAfterObjectNull() throws Exception {
   testDate.isAfter(null);
 }
Ejemplo n.º 12
0
 @Test(expectedExceptions = NullPointerException.class)
 public void testCompareToObjectNull() throws Exception {
   testDate.compareTo(null);
 }
Ejemplo n.º 13
0
 @BeforeTest
 public void setUp() throws Exception {
   testDate = MinguoDate.of(testEra, testYear, testMonthOfYear, testDayOfMonth);
 }
Ejemplo n.º 14
0
 // -----------------------------------------------------------------------
 // withDayOfMonth()
 // -----------------------------------------------------------------------
 @Test
 public void testWithDayOfMonth() {
   MinguoDate date = testDate.withDayOfMonth(4);
   assertEquals(date, MinguoDate.of(testYear, testMonthOfYear, 4));
 }
Ejemplo n.º 15
0
 // -----------------------------------------------------------------------
 // withDayOfYear()
 // -----------------------------------------------------------------------
 @Test
 public void testWithDayOfYear() {
   MinguoDate date = testDate.withDayOfYear(15);
   assertEquals(date, MinguoDate.of(testYear, MonthOfYear.JANUARY, 15));
 }
Ejemplo n.º 16
0
 // -----------------------------------------------------------------------
 // minusWeeks()
 // -----------------------------------------------------------------------
 @Test
 public void testMinusWeeks() {
   assertEquals(
       testDate.minusWeeks(2),
       MinguoDate.of(testYear, testMonthOfYear.previous(), 28 + testDayOfMonth - (2 * 7)));
 }
Ejemplo n.º 17
0
 // -----------------------------------------------------------------------
 // minusDays()
 // -----------------------------------------------------------------------
 @Test
 public void testMinusDays() {
   assertEquals(
       testDate.minusDays(2), MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth - 2));
 }
Ejemplo n.º 18
0
 // -----------------------------------------------------------------------
 // minusMonths()
 // -----------------------------------------------------------------------
 @Test
 public void testMinusMonths() {
   assertEquals(
       testDate.minusMonths(1),
       MinguoDate.of(testYear, testMonthOfYear.previous(), testDayOfMonth));
 }
Ejemplo n.º 19
0
 @Test(expectedExceptions = CalendricalException.class)
 public void testMinusYearsInvalidTooSmall() {
   testDate.minusYears(20000);
 }
Ejemplo n.º 20
0
 // -----------------------------------------------------------------------
 // minusYears()
 // -----------------------------------------------------------------------
 @Test
 public void testMinusYears() {
   assertEquals(
       testDate.minusYears(10), MinguoDate.of(testYear - 10, testMonthOfYear, testDayOfMonth));
 }
Ejemplo n.º 21
0
 // -----------------------------------------------------------------------
 // plusWeeks()
 // -----------------------------------------------------------------------
 @Test
 public void testPlusWeeks() {
   assertEquals(
       testDate.plusWeeks(2), MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth + (2 * 7)));
 }
Ejemplo n.º 22
0
 @Test
 public void testEqualsItselfTrue() throws Exception {
   assertEquals(testDate.equals(testDate), true);
 }
Ejemplo n.º 23
0
 @Test
 public void testEqualsStringFalse() throws Exception {
   assertEquals(testDate.equals("2009-07-15"), false);
 }
Ejemplo n.º 24
0
 // -----------------------------------------------------------------------
 // toLocalDate()
 // -----------------------------------------------------------------------
 @Test
 public void testToLocalDate() {
   assertEquals(
       MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth).toLocalDate(),
       LocalDate.of(testGregorianYear, testMonthOfYear, testDayOfMonth));
 }
Ejemplo n.º 25
0
 // -----------------------------------------------------------------------
 // toString()
 // -----------------------------------------------------------------------
 @Test
 public void testToString() {
   String expected = "98-03-03 (Minguo)";
   String actual = testDate.toString();
   assertEquals(expected, actual);
 }
Ejemplo n.º 26
0
 // -----------------------------------------------------------------------
 // compareTo(), isAfter(), isBefore(), and equals()
 // -----------------------------------------------------------------------
 @Test
 public void testCompareTo() throws Exception {
   doTestComparisons(
       MinguoDate.of(1, MonthOfYear.JANUARY, 1),
       MinguoDate.of(1, MonthOfYear.JANUARY, 2),
       MinguoDate.of(1, MonthOfYear.JANUARY, 31),
       MinguoDate.of(1, MonthOfYear.FEBRUARY, 1),
       MinguoDate.of(1, MonthOfYear.FEBRUARY, 28),
       MinguoDate.of(1, MonthOfYear.DECEMBER, 31),
       MinguoDate.of(2, MonthOfYear.JANUARY, 1),
       MinguoDate.of(2, MonthOfYear.DECEMBER, 31),
       MinguoDate.of(3, MonthOfYear.JANUARY, 1),
       MinguoDate.of(3, MonthOfYear.DECEMBER, 31),
       MinguoDate.of(9999, MonthOfYear.JANUARY, 1),
       MinguoDate.of(9999, MonthOfYear.DECEMBER, 31));
 }
Ejemplo n.º 27
0
 @Test
 public void test_factory_of_4() throws Exception {
   assertEquals(MinguoDate.of(testEra, testYear, testMonthOfYear, testDayOfMonth), testDate);
   assertMinguoDate(testDate, testEra, testYear, testMonthOfYear, testDayOfMonth);
 }
Ejemplo n.º 28
0
 void doTestComparisons(MinguoDate... dates) {
   for (int i = 0; i < dates.length; i++) {
     MinguoDate a = dates[i];
     for (int j = 0; j < dates.length; j++) {
       MinguoDate b = dates[j];
       if (i < j) {
         assertTrue(a.compareTo(b) < 0, a + " <=> " + b);
         assertEquals(a.isBefore(b), true, a + " <=> " + b);
         assertEquals(a.isAfter(b), false, a + " <=> " + b);
         assertEquals(a.equals(b), false, a + " <=> " + b);
       } else if (i > j) {
         assertTrue(a.compareTo(b) > 0, a + " <=> " + b);
         assertEquals(a.isBefore(b), false, a + " <=> " + b);
         assertEquals(a.isAfter(b), true, a + " <=> " + b);
         assertEquals(a.equals(b), false, a + " <=> " + b);
       } else {
         assertEquals(a.compareTo(b), 0, a + " <=> " + b);
         assertEquals(a.isBefore(b), false, a + " <=> " + b);
         assertEquals(a.isAfter(b), false, a + " <=> " + b);
         assertEquals(a.equals(b), true, a + " <=> " + b);
       }
     }
   }
 }
Ejemplo n.º 29
0
 @Test(expectedExceptions = NullPointerException.class)
 public void test_factory_of_3_invalidMonth() throws Exception {
   MinguoDate.of(testYear, null, testDayOfMonth);
 }
Ejemplo n.º 30
0
 // -----------------------------------------------------------------------
 // plusMonths()
 // -----------------------------------------------------------------------
 @Test
 public void testPlusMonths() {
   assertEquals(
       testDate.plusMonths(5), MinguoDate.of(testYear, testMonthOfYear.roll(5), testDayOfMonth));
 }