Search in sources :

Example 6 with TemporalAdjuster

use of java.time.temporal.TemporalAdjuster 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 7 with TemporalAdjuster

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

the class TCKOffsetTime method test_with_adjustment_AmPm.

@Test
public void test_with_adjustment_AmPm() {
    OffsetTime test = TEST_11_30_59_500_PONE.with(new TemporalAdjuster() {

        @Override
        public Temporal adjustInto(Temporal dateTime) {
            return dateTime.with(HOUR_OF_DAY, 23);
        }
    });
    assertEquals(test, OffsetTime.of(23, 30, 59, 500, OFFSET_PONE));
}
Also used : Temporal(java.time.temporal.Temporal) OffsetTime(java.time.OffsetTime) TemporalAdjuster(java.time.temporal.TemporalAdjuster) Test(org.testng.annotations.Test)

Example 8 with TemporalAdjuster

use of java.time.temporal.TemporalAdjuster 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 9 with TemporalAdjuster

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

the class TCKTemporalAdjusters method factory_ofDateAdjuster.

//-----------------------------------------------------------------------
// ofDateAdjuster()
//-----------------------------------------------------------------------
@Test
public void factory_ofDateAdjuster() {
    TemporalAdjuster test = TemporalAdjusters.ofDateAdjuster(date -> date.plusDays(2));
    assertEquals(LocalDate.of(2012, 6, 30).with(test), LocalDate.of(2012, 7, 2));
}
Also used : TemporalAdjuster(java.time.temporal.TemporalAdjuster) Test(org.testng.annotations.Test)

Example 10 with TemporalAdjuster

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

the class TCKChronoLocalDate method test_badWithAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDate date = chrono.date(refDate);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDate date2 = chrono2.date(refDate);
        TemporalAdjuster adjuster = new FixedAdjuster(date2);
        if (chrono != chrono2) {
            try {
                date.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException");
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDate result = date.with(adjuster);
            assertEquals(result, date2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) TemporalAdjuster(java.time.temporal.TemporalAdjuster) HijrahChronology(java.time.chrono.HijrahChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

TemporalAdjuster (java.time.temporal.TemporalAdjuster)10 Test (org.testng.annotations.Test)10 Temporal (java.time.temporal.Temporal)6 LocalDate (java.time.LocalDate)4 Chronology (java.time.chrono.Chronology)3 HijrahChronology (java.time.chrono.HijrahChronology)3 IsoChronology (java.time.chrono.IsoChronology)3 JapaneseChronology (java.time.chrono.JapaneseChronology)3 MinguoChronology (java.time.chrono.MinguoChronology)3 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)3 OffsetTime (java.time.OffsetTime)2 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetDateTime (java.time.OffsetDateTime)1 ChronoLocalDate (java.time.chrono.ChronoLocalDate)1