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);
}
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));
}
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);
}
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));
}
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");
}
}
}
Aggregations