@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()); }
@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); }
@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()); } }
@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()); } }
// ----------------------------------------------------------------------- // 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); }
// ----------------------------------------------------------------------- // 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)); }
// ----------------------------------------------------------------------- // plusMonths() // ----------------------------------------------------------------------- @Test public void testPlusMonths() { assertEquals( testDate.plusMonths(5), MinguoDate.of(testYear, testMonthOfYear.roll(5), testDayOfMonth)); }
// ----------------------------------------------------------------------- // minusWeeks() // ----------------------------------------------------------------------- @Test public void testMinusWeeks() { assertEquals( testDate.minusWeeks(2), MinguoDate.of(testYear, testMonthOfYear.previous(), 28 + testDayOfMonth - (2 * 7))); }
// ----------------------------------------------------------------------- // toLocalDate() // ----------------------------------------------------------------------- @Test public void testToLocalDate() { assertEquals( MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth).toLocalDate(), LocalDate.of(testGregorianYear, testMonthOfYear, testDayOfMonth)); }
// ----------------------------------------------------------------------- // minusMonths() // ----------------------------------------------------------------------- @Test public void testMinusMonths() { assertEquals( testDate.minusMonths(1), MinguoDate.of(testYear, testMonthOfYear.previous(), testDayOfMonth)); }
// ----------------------------------------------------------------------- // minusDays() // ----------------------------------------------------------------------- @Test public void testMinusDays() { assertEquals( testDate.minusDays(2), MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth - 2)); }
@Test(expectedExceptions = CalendricalException.class) public void test_factory_of_Calendrical_noData() throws Exception { MinguoDate.of(DateTimeFields.EMPTY); }
// ----------------------------------------------------------------------- // minusYears() // ----------------------------------------------------------------------- @Test public void testMinusYears() { assertEquals( testDate.minusYears(10), MinguoDate.of(testYear - 10, testMonthOfYear, testDayOfMonth)); }
@Test(expectedExceptions = NullPointerException.class) public void test_factory_of_Calendrical_null() throws Exception { MinguoDate.of((Calendrical) null); }
@Test public void testGetDayOfWeekCrossCheck() throws Exception { MinguoDate date = MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth); assertEquals(date.getDayOfWeek(), date.toLocalDate().getDayOfWeek()); }
// ----------------------------------------------------------------------- // withDayOfYear() // ----------------------------------------------------------------------- @Test public void testWithDayOfYear() { MinguoDate date = testDate.withDayOfYear(15); assertEquals(date, MinguoDate.of(testYear, MonthOfYear.JANUARY, 15)); }
// ----------------------------------------------------------------------- // withDayOfMonth() // ----------------------------------------------------------------------- @Test public void testWithDayOfMonth() { MinguoDate date = testDate.withDayOfMonth(4); assertEquals(date, MinguoDate.of(testYear, testMonthOfYear, 4)); }
// ----------------------------------------------------------------------- // withMonthOfYear() // ----------------------------------------------------------------------- @Test public void testWithMonthOfYear() { MinguoDate date = testDate.withMonthOfYear(MonthOfYear.APRIL); assertEquals(date, MinguoDate.of(testYear, MonthOfYear.APRIL, testDayOfMonth)); }
// ----------------------------------------------------------------------- // withYearOfEra() // ----------------------------------------------------------------------- @Test public void testWithYear() { MinguoDate date = testDate.withYear(MinguoEra.BEFORE_MINGUO, 100); assertEquals( date, MinguoDate.of(MinguoEra.BEFORE_MINGUO, 100, testMonthOfYear, testDayOfMonth)); }
// ----------------------------------------------------------------------- // withYearOfEra() // ----------------------------------------------------------------------- @Test public void testWithYearOfEra() { MinguoDate date = testDate.withYearOfEra(100); assertEquals(date, MinguoDate.of(100, testMonthOfYear, testDayOfMonth)); }
@Test public void test_factory_of_4() throws Exception { assertEquals(MinguoDate.of(testEra, testYear, testMonthOfYear, testDayOfMonth), testDate); assertMinguoDate(testDate, testEra, testYear, testMonthOfYear, testDayOfMonth); }
@BeforeTest public void setUp() throws Exception { testDate = MinguoDate.of(testEra, testYear, testMonthOfYear, testDayOfMonth); }
@Test(expectedExceptions = NullPointerException.class) public void test_factory_of_3_invalidMonth() throws Exception { MinguoDate.of(testYear, null, testDayOfMonth); }
// ----------------------------------------------------------------------- // plusWeeks() // ----------------------------------------------------------------------- @Test public void testPlusWeeks() { assertEquals( testDate.plusWeeks(2), MinguoDate.of(testYear, testMonthOfYear, testDayOfMonth + (2 * 7))); }