Search in sources :

Example 31 with ChronoPeriod

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());
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) Test(org.testng.annotations.Test)

Example 32 with ChronoPeriod

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);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) Test(org.testng.annotations.Test)

Example 33 with ChronoPeriod

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);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ChronoLocalDate(java.time.chrono.ChronoLocalDate) Test(org.testng.annotations.Test)

Example 34 with ChronoPeriod

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);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) Test(org.testng.annotations.Test)

Example 35 with ChronoPeriod

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");
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream) Test(org.testng.annotations.Test)

Aggregations

ChronoPeriod (java.time.chrono.ChronoPeriod)55 Test (org.testng.annotations.Test)26 Test (org.junit.Test)21 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 ChronoLocalDate (java.time.chrono.ChronoLocalDate)6 MinguoDate (java.time.chrono.MinguoDate)5 List (java.util.List)5 BigDecimal (java.math.BigDecimal)4 Period (java.time.Period)4 ChronoUnit (java.time.temporal.ChronoUnit)4 Temporal (java.time.temporal.Temporal)4 TemporalAccessor (java.time.temporal.TemporalAccessor)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Predicate (java.util.function.Predicate)4 Before (org.junit.Before)4 ComparablePeriod (org.kie.dmn.feel.lang.types.impl.ComparablePeriod)4 Duration (java.time.Duration)3 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)3 TemporalUnit (java.time.temporal.TemporalUnit)3