Search in sources :

Example 1 with TemporalAdjuster

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

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

the class TCKChronoZonedDateTime method test_badWithAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalAdjuster adjuster = new FixedAdjuster(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + czdt + ", supplied: " + czdt2);
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            ChronoZonedDateTime<?> result = czdt.with(adjuster);
            assertEquals(result, czdt2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : 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) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 3 with TemporalAdjuster

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

the class TCKChronoLocalDateTime method test_badWithAdjusterChrono.

@Test(dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoLocalDateTime<?> cdt = chrono.date(refDate).atTime(LocalTime.NOON);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
        TemporalAdjuster adjuster = new FixedAdjuster(cdt2);
        if (chrono != chrono2) {
            try {
                cdt.with(adjuster);
                Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: " + cdt2);
            } catch (ClassCastException cce) {
            // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoLocalDateTime<?> result = cdt.with(adjuster);
            assertEquals(result, cdt2, "WithAdjuster failed to replace date");
        }
    }
}
Also used : 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) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 4 with TemporalAdjuster

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

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

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