Search in sources :

Example 11 with MonthDay

use of java.time.MonthDay in project jdk8u_jdk by JetBrains.

the class TestMonthDay method doTest_comparisons_MonthDay.

void doTest_comparisons_MonthDay(MonthDay... localDates) {
    for (int i = 0; i < localDates.length; i++) {
        MonthDay a = localDates[i];
        for (int j = 0; j < localDates.length; j++) {
            MonthDay b = localDates[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);
            }
        }
    }
}
Also used : MonthDay(java.time.MonthDay)

Example 12 with MonthDay

use of java.time.MonthDay in project lucene-solr by apache.

the class TemporalEvaluatorsTest method testLimitedFunctions.

@Test
public void testLimitedFunctions() throws Exception {
    MonthDay monthDay = MonthDay.of(12, 5);
    testFunction("month(a)", monthDay, 12);
    testFunction("day(a)", monthDay, 5);
    try {
        testFunction("year(a)", monthDay, 2017);
        assertTrue(false);
    } catch (IOException e) {
        assertEquals("It is not possible to call 'year' function on java.time.MonthDay", e.getMessage());
    }
    YearMonth yearMonth = YearMonth.of(2018, 4);
    testFunction("month(a)", yearMonth, 4);
    testFunction("year(a)", yearMonth, 2018);
    try {
        testFunction("day(a)", yearMonth, 5);
        assertTrue(false);
    } catch (IOException e) {
        assertEquals("It is not possible to call 'day' function on java.time.YearMonth", e.getMessage());
    }
}
Also used : YearMonth(java.time.YearMonth) MonthDay(java.time.MonthDay) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with MonthDay

use of java.time.MonthDay in project jdk8u_jdk by JetBrains.

the class TestMonthDay method test_withMonth_int_noChangeSame.

@Test
public void test_withMonth_int_noChangeSame() {
    MonthDay test = MonthDay.of(6, 30);
    assertSame(test.withMonth(6), test);
}
Also used : MonthDay(java.time.MonthDay) Test(org.testng.annotations.Test)

Example 14 with MonthDay

use of java.time.MonthDay in project jdk8u_jdk by JetBrains.

the class TestMonthDay method test_withDayOfMonth_noChangeSame.

@Test
public void test_withDayOfMonth_noChangeSame() {
    MonthDay test = MonthDay.of(6, 30);
    assertSame(test.withDayOfMonth(30), test);
}
Also used : MonthDay(java.time.MonthDay) Test(org.testng.annotations.Test)

Example 15 with MonthDay

use of java.time.MonthDay in project jdk8u_jdk by JetBrains.

the class TCKMonthDay method now_Clock.

//-----------------------------------------------------------------------
// now(Clock)
//-----------------------------------------------------------------------
@Test
public void now_Clock() {
    Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
    Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
    MonthDay test = MonthDay.now(clock);
    assertEquals(test.getMonth(), Month.DECEMBER);
    assertEquals(test.getDayOfMonth(), 31);
}
Also used : Instant(java.time.Instant) MonthDay(java.time.MonthDay) Clock(java.time.Clock) Test(org.testng.annotations.Test)

Aggregations

MonthDay (java.time.MonthDay)28 Test (org.testng.annotations.Test)25 LocalDate (java.time.LocalDate)4 IOException (java.io.IOException)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 YearMonth (java.time.YearMonth)1 ZoneId (java.time.ZoneId)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Test (org.junit.Test)1