use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TCKValueRangeSerialization method test_valueRangeSerialized.
/**
* Verify Serialized bytes of a ValueRange.
* @throws IOException if thrown during serialization is an unexpected test tailure
*/
public void test_valueRangeSerialized() throws IOException {
byte[] expected = { (byte) 172, (byte) 237, 0, 5, 115, 114, 0, 29, 106, 97, /* ¬ í s r j a */
118, 97, 46, 116, 105, 109, 101, 46, 116, 101, /* v a . t i m e . t e */
109, 112, 111, 114, 97, 108, 46, 86, 97, 108, /* m p o r a l . V a l */
117, 101, 82, 97, 110, 103, 101, (byte) 154, 113, (byte) 169, /* u e R a n g e q © */
86, (byte) 242, (byte) 205, 90, (byte) 184, 2, 0, 4, 74, 0, /* V ò Í Z ¸ J */
10, 109, 97, 120, 76, 97, 114, 103, 101, 115, /* m a x L a r g e s */
116, 74, 0, 11, 109, 97, 120, 83, 109, 97, /* t J m a x S m a */
108, 108, 101, 115, 116, 74, 0, 10, 109, 105, /* l l e s t J m i */
110, 76, 97, 114, 103, 101, 115, 116, 74, 0, /* n L a r g e s t J */
11, 109, 105, 110, 83, 109, 97, 108, 108, 101, /* m i n S m a l l e */
115, 116, 120, 112, 0, 0, 0, 0, 0, 0, /* s t x p */
0, 40, 0, 0, 0, 0, 0, 0, 0, 30, /* ( */
0, 0, 0, 0, 0, 0, 0, 20, 0, 0, /* */
0, 0, 0, 0, 0, 10 };
ValueRange range = ValueRange.of(10, 20, 30, 40);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(range);
byte[] actual = baos.toByteArray();
assertEquals(actual, expected, "Serialized bytes incorrect");
}
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_withWeekOfWeekBasedYear.
@Test(dataProvider = "weekFields")
public void test_withWeekOfWeekBasedYear(DayOfWeek firstDayOfWeek, int minDays) {
LocalDate day = LocalDate.of(2012, 12, 31);
WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
TemporalField dowField = week.dayOfWeek();
TemporalField wowbyField = week.weekOfWeekBasedYear();
TemporalField yowbyField = week.weekBasedYear();
int dowExpected = (day.get(dowField) - 1) % 7 + 1;
LocalDate dowDate = day.with(dowField, dowExpected);
int dowResult = dowDate.get(dowField);
assertEquals(dowResult, dowExpected, "Localized DayOfWeek not correct; " + day + " -->" + dowDate);
int weekExpected = day.get(wowbyField) + 1;
ValueRange range = day.range(wowbyField);
weekExpected = ((weekExpected - 1) % (int) range.getMaximum()) + 1;
LocalDate weekDate = day.with(wowbyField, weekExpected);
int weekResult = weekDate.get(wowbyField);
assertEquals(weekResult, weekExpected, "Localized WeekOfWeekBasedYear not correct; " + day + " -->" + weekDate);
int yearExpected = day.get(yowbyField) + 1;
LocalDate yearDate = day.with(yowbyField, yearExpected);
int yearResult = yearDate.get(yowbyField);
assertEquals(yearResult, yearExpected, "Localized WeekBasedYear not correct; " + day + " --> " + yearDate);
range = yearDate.range(wowbyField);
weekExpected = Math.min(day.get(wowbyField), (int) range.getMaximum());
int weekActual = yearDate.get(wowbyField);
assertEquals(weekActual, weekExpected, "Localized WeekOfWeekBasedYear week should not change; " + day + " --> " + yearDate + ", actual: " + weekActual + ", weekExpected: " + weekExpected);
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TCKWeekFields method test_fieldRanges.
@Test(dataProvider = "weekFields")
public void test_fieldRanges(DayOfWeek firstDayOfWeek, int minDays) {
WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
TemporalField womField = weekDef.weekOfMonth();
TemporalField woyField = weekDef.weekOfYear();
LocalDate day = LocalDate.of(2012, 11, 30);
LocalDate endDay = LocalDate.of(2013, 1, 2);
while (day.isBefore(endDay)) {
LocalDate last = day.with(DAY_OF_MONTH, day.lengthOfMonth());
int lastWOM = last.get(womField);
LocalDate first = day.with(DAY_OF_MONTH, 1);
int firstWOM = first.get(womField);
ValueRange rangeWOM = day.range(womField);
assertEquals(rangeWOM.getMinimum(), firstWOM, "Range min should be same as WeekOfMonth for first day of month: " + first + ", " + weekDef);
assertEquals(rangeWOM.getMaximum(), lastWOM, "Range max should be same as WeekOfMonth for last day of month: " + last + ", " + weekDef);
last = day.with(DAY_OF_YEAR, day.lengthOfYear());
int lastWOY = last.get(woyField);
first = day.with(DAY_OF_YEAR, 1);
int firstWOY = first.get(woyField);
ValueRange rangeWOY = day.range(woyField);
assertEquals(rangeWOY.getMinimum(), firstWOY, "Range min should be same as WeekOfYear for first day of Year: " + day + ", " + weekDef);
assertEquals(rangeWOY.getMaximum(), lastWOY, "Range max should be same as WeekOfYear for last day of Year: " + day + ", " + weekDef);
day = day.plusDays(1);
}
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TestDateTimeValueRange method test_of_longlong_big.
public void test_of_longlong_big() {
ValueRange test = ValueRange.of(1, 123456789012345L);
assertEquals(test.getMinimum(), 1);
assertEquals(test.getLargestMinimum(), 1);
assertEquals(test.getSmallestMaximum(), 123456789012345L);
assertEquals(test.getMaximum(), 123456789012345L);
assertEquals(test.isFixed(), true);
assertEquals(test.isIntValue(), false);
}
use of java.time.temporal.ValueRange in project jdk8u_jdk by JetBrains.
the class TestDateTimeValueRange method test_of_checkValidValueMinException.
@Test(dataProvider = "valid", expectedExceptions = DateTimeException.class)
public void test_of_checkValidValueMinException(long sMin, long lMin, long sMax, long lMax) {
ValueRange test = ValueRange.of(sMin, lMin, sMax, lMax);
test.checkValidIntValue(sMin - 1, null);
}
Aggregations