Search in sources :

Example 21 with Temporal

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

the class TCKOffsetTime method test_with_adjustment.

//-----------------------------------------------------------------------
// with(WithAdjuster)
//-----------------------------------------------------------------------
@Test
public void test_with_adjustment() {
    final OffsetTime sample = OffsetTime.of(23, 5, 0, 0, OFFSET_PONE);
    TemporalAdjuster adjuster = new TemporalAdjuster() {

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

Example 22 with Temporal

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

the class TCKYear method test_adjustDate.

//-----------------------------------------------------------------------
// adjustInto()
//-----------------------------------------------------------------------
@Test
public void test_adjustDate() {
    LocalDate base = LocalDate.of(2007, 2, 12);
    for (int i = -4; i <= 2104; i++) {
        Temporal result = Year.of(i).adjustInto(base);
        assertEquals(result, LocalDate.of(i, 2, 12));
    }
}
Also used : Temporal(java.time.temporal.Temporal) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 23 with Temporal

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

the class TCKYear method test_with_TemporalAdjuster.

//-----------------------------------------------------------------------
// with(TemporalAdjuster)
//-----------------------------------------------------------------------
@Test
public void test_with_TemporalAdjuster() {
    Year base = Year.of(-10);
    for (int i = -4; i <= 2104; i++) {
        Temporal result = base.with(Year.of(i));
        assertEquals(result, Year.of(i));
    }
}
Also used : Year(java.time.Year) Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Example 24 with Temporal

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

the class TCKChronoUnit method test_unitAndTemporal.

@Test(dataProvider = "unitAndTemporal")
public void test_unitAndTemporal(ChronoUnit unit, Temporal base, boolean isSupportedBy, long amount, Temporal target) {
    assertEquals(unit.isSupportedBy(base), isSupportedBy);
    if (isSupportedBy) {
        Temporal result = unit.addTo(base, amount);
        assertEquals(result, target);
        assertEquals(unit.between(base, result), amount);
    }
}
Also used : Temporal(java.time.temporal.Temporal) Test(org.testng.annotations.Test)

Example 25 with Temporal

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

the class TCKLocalDateTime method test_adjustInto.

@Test(dataProvider = "adjustInto")
public void test_adjustInto(LocalDateTime 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) Test(org.testng.annotations.Test)

Aggregations

Temporal (java.time.temporal.Temporal)37 Test (org.testng.annotations.Test)24 TemporalAmount (java.time.temporal.TemporalAmount)12 Duration (java.time.Duration)7 DateTimeParseException (java.time.format.DateTimeParseException)7 TemporalUnit (java.time.temporal.TemporalUnit)7 DateTimeException (java.time.DateTimeException)6 LocalDate (java.time.LocalDate)6 LocalDateTime (java.time.LocalDateTime)6 TemporalAdjuster (java.time.temporal.TemporalAdjuster)6 LocalTime (java.time.LocalTime)5 ZonedDateTime (java.time.ZonedDateTime)5 ArrayList (java.util.ArrayList)5 Period (java.time.Period)4 DataRow (org.knime.core.data.DataRow)4 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 DataCell (org.knime.core.data.DataCell)3 RowKey (org.knime.core.data.RowKey)3