Search in sources :

Example 1 with HijrahDate

use of java.time.chrono.HijrahDate in project jdk8u_jdk by JetBrains.

the class TCKHijrahChronology method test_resolve_ymd_strict.

@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected, "Resolved to incorrect date");
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed, returned: " + date);
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : HijrahDate(java.time.chrono.HijrahDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 2 with HijrahDate

use of java.time.chrono.HijrahDate in project jdk8u_jdk by JetBrains.

the class TCKHijrahChronology method test_resolve_ymd_lenient.

@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_lenient(int y, int m, int d, HijrahDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (expected != null) {
        HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
            fail("Should have failed, returned: " + date);
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : HijrahDate(java.time.chrono.HijrahDate) TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 3 with HijrahDate

use of java.time.chrono.HijrahDate in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDateSerialization method test_hijrahSerialization_format.

//-----------------------------------------------------------------------
// Test HijrajDate serialization is a type, Chronology, year, month, day
//-----------------------------------------------------------------------
@Test()
public void test_hijrahSerialization_format() throws Exception {
    HijrahChronology chrono = HijrahChronology.INSTANCE;
    HijrahDate date = HijrahDate.of(1433, 10, 29);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Expect the type of the HijrahDate in the stream
    byte[] hijrahDateBytes = new byte[] { HIJRAH_DATE_TYPE };
    // Literal reference to Hijrah-Umalqura Chronology
    byte[] hijrahChronoBytes = new byte[] { 115, 113, 0, 126, 0, 0, /* p w   s q  ~   */
    119, 18, 1, 0, 15, 72, 105, 106, 114, 97, /* w     H i j r a */
    104, 45, 117, 109, 97, 108, 113, 117, 114, 97, /* h - u m a l q u r a */
    120 };
    // Build the sequence that represents the data in the stream
    baos = new ByteArrayOutputStream();
    try (DataOutputStream dos = new DataOutputStream(baos)) {
        dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA);
        // 6 bytes follow
        dos.writeByte(6);
        dos.writeInt(date.get(YEAR));
        dos.writeByte(date.get(MONTH_OF_YEAR));
        dos.writeByte(date.get(DAY_OF_MONTH));
        dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
    }
    byte[] dateBytes = baos.toByteArray();
    assertSerializedBySer(date, hijrahDateBytes, hijrahChronoBytes, dateBytes);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) DataOutputStream(java.io.DataOutputStream) HijrahChronology(java.time.chrono.HijrahChronology) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 4 with HijrahDate

use of java.time.chrono.HijrahDate in project jdk8u_jdk by JetBrains.

the class TCKHijrahChronology method test_ofYearDayTooLarge.

// Negative test or dateYearDay with day too large
@Test(expectedExceptions = java.time.DateTimeException.class)
public void test_ofYearDayTooLarge() {
    int year = 1435;
    int lengthOfYear = HijrahChronology.INSTANCE.dateYearDay(year, 1).lengthOfYear();
    HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(year, lengthOfYear + 1);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) Test(org.testng.annotations.Test)

Example 5 with HijrahDate

use of java.time.chrono.HijrahDate in project jdk8u_jdk by JetBrains.

the class TCKHijrahChronology method test_resolve_yearOfEra_eraAndYearOnly_valid.

@Test(dataProvider = "resolve_styleByEra")
public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, HijrahEra era) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR, 1343L);
    HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
    assertEquals(date, null);
    assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
    assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1343L);
    assertEquals(fieldValues.size(), 2);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) TemporalField(java.time.temporal.TemporalField) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

HijrahDate (java.time.chrono.HijrahDate)26 Test (org.testng.annotations.Test)25 TemporalField (java.time.temporal.TemporalField)11 HashMap (java.util.HashMap)11 DateTimeException (java.time.DateTimeException)6 HijrahChronology (java.time.chrono.HijrahChronology)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 OffsetDateTime (java.time.OffsetDateTime)1 ZonedDateTime (java.time.ZonedDateTime)1 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ValueRange (java.time.temporal.ValueRange)1 AbstractTCKTest (tck.java.time.AbstractTCKTest)1