use of java.time.chrono.ChronoPeriod in project jdk8u_jdk by JetBrains.
the class TCKChronoPeriod method test_equals_equal.
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_equals_equal(Chronology chrono) {
ChronoPeriod a1 = chrono.period(1, 2, 3);
ChronoPeriod a2 = chrono.period(1, 2, 3);
assertEquals(a1, a1);
assertEquals(a1, a2);
assertEquals(a2, a1);
assertEquals(a2, a2);
assertEquals(a1.hashCode(), a2.hashCode());
}
use of java.time.chrono.ChronoPeriod in project jdk8u_jdk by JetBrains.
the class TCKChronoPeriod method test_isZero_isNegative.
@Test(dataProvider = "calendars")
public void test_isZero_isNegative(Chronology chrono) {
ChronoPeriod periodPositive = chrono.period(1, 2, 3);
assertEquals(periodPositive.isZero(), false);
assertEquals(periodPositive.isNegative(), false);
ChronoPeriod periodZero = chrono.period(0, 0, 0);
assertEquals(periodZero.isZero(), true);
assertEquals(periodZero.isNegative(), false);
ChronoPeriod periodNegative = chrono.period(-1, 0, 0);
assertEquals(periodNegative.isZero(), false);
assertEquals(periodNegative.isNegative(), true);
}
use of java.time.chrono.ChronoPeriod in project jdk8u_jdk by JetBrains.
the class TCKChronoPeriod method test_addTo_wrongChrono.
@Test(dataProvider = "calendars", expectedExceptions = DateTimeException.class)
public void test_addTo_wrongChrono(Chronology chrono) {
ChronoPeriod period = chrono.period(1, 2, 3);
ChronoLocalDate isoDate = LocalDate.of(2000, 1, 1);
ChronoLocalDate thaiDate = ThaiBuddhistChronology.INSTANCE.date(2000, 1, 1);
// one of these two will fail
period.addTo(isoDate);
period.addTo(thaiDate);
}
use of java.time.chrono.ChronoPeriod in project jdk8u_jdk by JetBrains.
the class TCKChronoPeriod method test_get.
@Test(dataProvider = "calendars")
public void test_get(Chronology chrono) {
ChronoPeriod period = chrono.period(1, 2, 3);
assertEquals(period.get(YEARS), 1);
assertEquals(period.get(MONTHS), 2);
assertEquals(period.get(DAYS), 3);
}
use of java.time.chrono.ChronoPeriod in project jdk8u_jdk by JetBrains.
the class TCKChronoPeriod method test_serialization.
//-----------------------------------------------------------------------
// Test Serialization of Calendars
//-----------------------------------------------------------------------
@Test(dataProvider = "calendars")
public void test_serialization(Chronology chrono) throws Exception {
ChronoPeriod period = chrono.period(1, 2, 3);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(baos);
out.writeObject(period);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream in = new ObjectInputStream(bais);
ChronoPeriod ser = (ChronoPeriod) in.readObject();
assertEquals(ser, period, "deserialized ChronoPeriod is wrong");
}
Aggregations