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