Search in sources :

Example 1 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKLocalDateTime method test_with_adjustment.

//-----------------------------------------------------------------------
// with()
//-----------------------------------------------------------------------
@Test
public void test_with_adjustment() {
    final LocalDateTime sample = LocalDateTime.of(2012, 3, 4, 23, 5);
    TemporalAdjuster adjuster = new TemporalAdjuster() {

        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_2007_07_15_12_30_40_987654321.with(adjuster), sample);
}
Also used : LocalDateTime(java.time.LocalDateTime) Temporal(java.time.temporal.Temporal) TemporalAdjuster(java.time.temporal.TemporalAdjuster) Test(org.testng.annotations.Test)

Example 2 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKChronoPeriod method test_addTo.

//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_addTo(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.addTo(date);
    assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ChronoLocalDate(java.time.chrono.ChronoLocalDate) Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Example 3 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKChronoPeriod method test_subtractFrom.

@Test(dataProvider = "calendars")
public void test_subtractFrom(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.subtractFrom(date);
    assertEquals(result, date.minus(14, MONTHS).minus(3, DAYS));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ChronoLocalDate(java.time.chrono.ChronoLocalDate) Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Example 4 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKLocalDate method test_with_adjustment.

//-----------------------------------------------------------------------
// with()
//-----------------------------------------------------------------------
@Test
public void test_with_adjustment() {
    final LocalDate sample = LocalDate.of(2012, 3, 4);
    TemporalAdjuster adjuster = new TemporalAdjuster() {

        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return sample;
        }
    };
    assertEquals(TEST_2007_07_15.with(adjuster), sample);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalAdjuster(java.time.temporal.TemporalAdjuster) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 5 with Temporal

use of java.time.temporal.Temporal in project jdk8u_jdk by JetBrains.

the class TCKLocalTime method test_adjustInto.

@Test(dataProvider = "adjustInto")
public void test_adjustInto(LocalTime test, Temporal temporal, Temporal expected, Class<?> expectedEx) {
    if (expectedEx == null) {
        Temporal result = test.adjustInto(temporal);
        assertEquals(result, expected);
    } else {
        try {
            Temporal result = test.adjustInto(temporal);
            fail();
        } catch (Exception ex) {
            assertTrue(expectedEx.isInstance(ex));
        }
    }
}
Also used : Temporal(java.time.temporal.Temporal) DateTimeException(java.time.DateTimeException) DateTimeParseException(java.time.format.DateTimeParseException) UnsupportedTemporalTypeException(java.time.temporal.UnsupportedTemporalTypeException) Test(org.testng.annotations.Test)

Aggregations

Temporal (java.time.temporal.Temporal)24 Test (org.testng.annotations.Test)24 TemporalAmount (java.time.temporal.TemporalAmount)7 TemporalUnit (java.time.temporal.TemporalUnit)7 TemporalAdjuster (java.time.temporal.TemporalAdjuster)6 DateTimeException (java.time.DateTimeException)5 DateTimeParseException (java.time.format.DateTimeParseException)5 ArrayList (java.util.ArrayList)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LocalDate (java.time.LocalDate)2 LocalTime (java.time.LocalTime)2 OffsetTime (java.time.OffsetTime)2 ChronoLocalDate (java.time.chrono.ChronoLocalDate)2 ChronoPeriod (java.time.chrono.ChronoPeriod)2 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)2 Duration (java.time.Duration)1 LocalDateTime (java.time.LocalDateTime)1 OffsetDateTime (java.time.OffsetDateTime)1 Year (java.time.Year)1 MINUTE_OF_HOUR (java.time.temporal.ChronoField.MINUTE_OF_HOUR)1