Search in sources :

Example 11 with Temporal

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

the class TCKInstant method test_adjustInto.

@Test(dataProvider = "adjustInto")
public void test_adjustInto(Instant 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) UnsupportedTemporalTypeException(java.time.temporal.UnsupportedTemporalTypeException) DateTimeParseException(java.time.format.DateTimeParseException) Test(org.testng.annotations.Test)

Example 12 with Temporal

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

the class TCKLocalTime method test_with_adjustment.

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

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

Example 13 with Temporal

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

the class TCKOffsetDateTime method test_with_adjustment.

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

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

Example 14 with Temporal

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

the class TCKOffsetDateTime method test_adjustInto.

@Test(dataProvider = "adjustInto")
public void test_adjustInto(OffsetDateTime 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) InvocationTargetException(java.lang.reflect.InvocationTargetException) DateTimeParseException(java.time.format.DateTimeParseException) Test(org.testng.annotations.Test)

Example 15 with Temporal

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

the class TCKPeriod method test_minus_TemporalAmount_DaysHours.

@Test(expectedExceptions = DateTimeException.class)
public void test_minus_TemporalAmount_DaysHours() {
    TemporalAmount amount = new TemporalAmount() {

        @Override
        public long get(TemporalUnit unit) {
            if (unit == DAYS) {
                return 1;
            } else {
                return 2;
            }
        }

        @Override
        public List<TemporalUnit> getUnits() {
            List<TemporalUnit> list = new ArrayList<>();
            list.add(DAYS);
            list.add(HOURS);
            return list;
        }

        @Override
        public Temporal addTo(Temporal temporal) {
            throw new UnsupportedOperationException();
        }

        @Override
        public Temporal subtractFrom(Temporal temporal) {
            throw new UnsupportedOperationException();
        }
    };
    pymd(4, 5, 6).minus(amount);
}
Also used : Temporal(java.time.temporal.Temporal) TemporalUnit(java.time.temporal.TemporalUnit) TemporalAmount(java.time.temporal.TemporalAmount) ArrayList(java.util.ArrayList) 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