Search in sources :

Example 11 with DayOfWeek

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

the class TCKLocalDate method test_getDayOfWeek.

@Test
public void test_getDayOfWeek() {
    DayOfWeek dow = DayOfWeek.MONDAY;
    for (Month month : Month.values()) {
        int length = month.length(false);
        for (int i = 1; i <= length; i++) {
            LocalDate d = LocalDate.of(2007, month, i);
            assertSame(d.getDayOfWeek(), dow);
            dow = dow.plus(1);
        }
    }
}
Also used : DayOfWeek(java.time.DayOfWeek) Month(java.time.Month) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 12 with DayOfWeek

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

the class TCKDayOfWeek method test_factory_int_singleton.

//-----------------------------------------------------------------------
@Test
public void test_factory_int_singleton() {
    for (int i = 1; i <= 7; i++) {
        DayOfWeek test = DayOfWeek.of(i);
        assertEquals(test.getValue(), i);
        assertSame(DayOfWeek.of(i), test);
    }
}
Also used : DayOfWeek(java.time.DayOfWeek) Test(org.testng.annotations.Test)

Example 13 with DayOfWeek

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

the class TCKTemporalAdjusters method test_nextOrCurrent.

@Test
public void test_nextOrCurrent() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);
            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.nextOrSame(dow).adjustInto(date);
                assertSame(test.getDayOfWeek(), dow);
                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff < 8);
                    assertEquals(date.equals(test), date.getDayOfWeek() == dow);
                } else {
                    assertFalse(date.getDayOfWeek() == dow);
                    assertSame(month, Month.DECEMBER);
                    assertTrue(date.getDayOfMonth() > 24);
                    assertEquals(test.getYear(), 2008);
                    assertSame(test.getMonth(), Month.JANUARY);
                    assertTrue(test.getDayOfMonth() < 8);
                }
            }
        }
    }
}
Also used : Month(java.time.Month) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 14 with DayOfWeek

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

the class TCKTemporalAdjusters method test_previous.

@Test
public void test_previous() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);
            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.previous(dow).adjustInto(date);
                assertSame(test.getDayOfWeek(), dow, date + " " + test);
                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
                } else {
                    assertSame(month, Month.JANUARY);
                    assertTrue(date.getDayOfMonth() < 8);
                    assertEquals(test.getYear(), 2006);
                    assertSame(test.getMonth(), Month.DECEMBER);
                    assertTrue(test.getDayOfMonth() > 24);
                }
            }
        }
    }
}
Also used : Month(java.time.Month) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 15 with DayOfWeek

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

the class TCKTemporalAdjusters method test_next.

@Test
public void test_next() {
    for (Month month : Month.values()) {
        for (int i = 1; i <= month.length(false); i++) {
            LocalDate date = date(2007, month, i);
            for (DayOfWeek dow : DayOfWeek.values()) {
                LocalDate test = (LocalDate) TemporalAdjusters.next(dow).adjustInto(date);
                assertSame(test.getDayOfWeek(), dow, date + " " + test);
                if (test.getYear() == 2007) {
                    int dayDiff = test.getDayOfYear() - date.getDayOfYear();
                    assertTrue(dayDiff > 0 && dayDiff < 8);
                } else {
                    assertSame(month, Month.DECEMBER);
                    assertTrue(date.getDayOfMonth() > 24);
                    assertEquals(test.getYear(), 2008);
                    assertSame(test.getMonth(), Month.JANUARY);
                    assertTrue(test.getDayOfMonth() < 8);
                }
            }
        }
    }
}
Also used : Month(java.time.Month) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

DayOfWeek (java.time.DayOfWeek)18 LocalDate (java.time.LocalDate)10 Test (org.testng.annotations.Test)9 Month (java.time.Month)8 LocalDateTime (java.time.LocalDateTime)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 WeekFields (java.time.temporal.WeekFields)2 DataProvider (org.testng.annotations.DataProvider)2 Instant (java.time.Instant)1 LocalTime (java.time.LocalTime)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 TemporalField (java.time.temporal.TemporalField)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 Locale (java.util.Locale)1 Callable (java.util.concurrent.Callable)1 AbstractTCKTest (tck.java.time.AbstractTCKTest)1