java.time.DateTimeException Java Examples
The following examples show how to use
java.time.DateTimeException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TCKThaiBuddhistChronology.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "resolve_ymd") public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate 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) { ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT); assertEquals(date, expected); assertEquals(fieldValues.size(), 0); } else { try { ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT); fail("Should have failed"); } catch (DateTimeException ex) { // expected } } }
Example #2
Source File: TCKIsoChronology.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "resolve_yearOfEra") public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) { Map<TemporalField, Long> fieldValues = new HashMap<>(); if (e != null) { fieldValues.put(ChronoField.ERA, (long) e); } if (yoe != null) { fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe); } if (y != null) { fieldValues.put(ChronoField.YEAR, (long) y); } if (field != null) { LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, style); assertEquals(date, null); assertEquals(fieldValues.get(field), (Long) expected.longValue()); assertEquals(fieldValues.size(), 1); } else { try { IsoChronology.INSTANCE.resolveDate(fieldValues, style); fail("Should have failed"); } catch (DateTimeException ex) { // expected } } }
Example #3
Source File: TCKDateTimeFormatter.java From hottub with GNU General Public License v2.0 | 6 votes |
@Test public void test_resolverFields_selectOneDateResolveYD() throws Exception { DateTimeFormatter base = new DateTimeFormatterBuilder() .appendValue(YEAR).appendLiteral('-').appendValue(MONTH_OF_YEAR).appendLiteral('-') .appendValue(DAY_OF_MONTH).appendLiteral('-').appendValue(DAY_OF_YEAR).toFormatter(); DateTimeFormatter f = base.withResolverFields(YEAR, DAY_OF_YEAR); Set<TemporalField> expected = new HashSet<>(Arrays.asList(YEAR, DAY_OF_YEAR)); // Use set.equals(); testNG comparison of Collections is ordered assertTrue(f.getResolverFields().equals(expected), "ResolveFields: " + f.getResolverFields()); try { base.parse("2012-6-30-321", LocalDate::from); // wrong month/day-of-month fail(); } catch (DateTimeException ex) { // expected, fails as it produces two different dates } LocalDate parsed = f.parse("2012-6-30-321", LocalDate::from); // ignored month/day-of-month assertEquals(parsed, LocalDate.of(2012, 11, 16)); }
Example #4
Source File: TCKIsoChronology.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider = "resolve_ymaa") public void test_resolve_ymaa_strict(int y, int m, int w, int d, LocalDate expected, boolean 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.ALIGNED_WEEK_OF_MONTH, (long) w); fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d); if (strict) { LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT); assertEquals(date, expected); assertEquals(fieldValues.size(), 0); } else { try { IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT); fail("Should have failed"); } catch (DateTimeException ex) { // expected } } }
Example #5
Source File: TCKInstant.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="with") Object[][] data_with() { return new Object[][]{ {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(20), null}, {Instant.ofEpochSecond(10), Instant.ofEpochSecond(20, -100), Instant.ofEpochSecond(20, -100), null}, {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(0), null}, {Instant.ofEpochSecond(10), Instant.MIN, Instant.MIN, null}, {Instant.ofEpochSecond(10), Instant.MAX, Instant.MAX, null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(20), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class}, }; }
Example #6
Source File: TCKInstant.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="adjustInto") Object[][] data_adjustInto() { return new Object[][]{ {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null}, {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null}, {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null}, {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class}, }; }
Example #7
Source File: TCKInstant.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="adjustInto") Object[][] data_adjustInto() { return new Object[][]{ {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null}, {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null}, {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null}, {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null}, {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null}, {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class}, }; }
Example #8
Source File: TCKZoneOffset.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Test public void test_factory_string_invalid() { String[] values = new String[] { "","A","B","C","D","E","F","G","H","I","J","K","L","M", "N","O","P","Q","R","S","T","U","V","W","X","Y","ZZ", "0", "+0:00","+00:0","+0:0", "+000","+00000", "+0:00:00","+00:0:00","+00:00:0","+0:0:0","+0:0:00","+00:0:0","+0:00:0", "1", "+01_00","+01;00","+01@00","+01:AA", "+19","+19:00","+18:01","+18:00:01","+1801","+180001", "-0:00","-00:0","-0:0", "-000","-00000", "-0:00:00","-00:0:00","-00:00:0","-0:0:0","-0:0:00","-00:0:0","-0:00:0", "-19","-19:00","-18:01","-18:00:01","-1801","-180001", "-01_00","-01;00","-01@00","-01:AA", "@01:00", }; for (int i = 0; i < values.length; i++) { try { ZoneOffset.of(values[i]); fail("Should have failed:" + values[i]); } catch (DateTimeException ex) { // expected } } }
Example #9
Source File: TCKLocalTime.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@DataProvider(name="adjustInto") Object[][] data_adjustInto() { return new Object[][]{ {LocalTime.of(23, 5), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 0, 0), null}, {LocalTime.of(23, 5, 20), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 0), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.of(4, 1, 1, 100), LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.of(23, 5, 20, 1000), LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), null}, {LocalTime.MAX, LocalTime.of(23, 5, 20, 1000), LocalTime.of(23, 59, 59, 999999999), null}, {LocalTime.MIN, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null}, {LocalTime.NOON, LocalTime.of(23, 5, 20, 1000), LocalTime.of(12, 0, 0), null}, {LocalTime.MIDNIGHT, LocalTime.of(23, 5, 20, 1000), LocalTime.of(0, 0, 0), null}, {LocalTime.of(23, 5), LocalDateTime.of(2210, 2, 2, 1, 1), LocalDateTime.of(2210, 2, 2, 23, 5), null}, {LocalTime.of(23, 5), OffsetTime.of(1, 1, 0, 0, OFFSET_PTWO), OffsetTime.of(23, 5, 0, 0, OFFSET_PTWO), null}, {LocalTime.of(23, 5), OffsetDateTime.of(2210, 2, 2, 1, 1, 0, 0, OFFSET_PTWO), OffsetDateTime.of(2210, 2, 2, 23, 5, 0, 0, OFFSET_PTWO), null}, {LocalTime.of(23, 5), ZonedDateTime.of(2210, 2, 2, 1, 1, 0, 0, ZONE_PARIS), ZonedDateTime.of(2210, 2, 2, 23, 5, 0, 0, ZONE_PARIS), null}, {LocalTime.of(23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class}, {LocalTime.of(23, 5), null, null, NullPointerException.class}, }; }
Example #10
Source File: DateTimeFormatter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Formats a date-time object to an {@code Appendable} using this formatter. * <p> * This outputs the formatted date-time to the specified destination. * {@link Appendable} is a general purpose interface that is implemented by all * key character output classes including {@code StringBuffer}, {@code StringBuilder}, * {@code PrintStream} and {@code Writer}. * <p> * Although {@code Appendable} methods throw an {@code IOException}, this method does not. * Instead, any {@code IOException} is wrapped in a runtime exception. * * @param temporal the temporal object to format, not null * @param appendable the appendable to format to, not null * @throws DateTimeException if an error occurs during formatting */ public void formatTo(TemporalAccessor temporal, Appendable appendable) { Objects.requireNonNull(temporal, "temporal"); Objects.requireNonNull(appendable, "appendable"); try { DateTimePrintContext context = new DateTimePrintContext(temporal, this); if (appendable instanceof StringBuilder) { printerParser.format(context, (StringBuilder) appendable); } else { // buffer output to avoid writing to appendable in case of error StringBuilder buf = new StringBuilder(32); printerParser.format(context, buf); appendable.append(buf); } } catch (IOException ex) { throw new DateTimeException(ex.getMessage(), ex); } }
Example #11
Source File: TestReducedPrinter.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="Pivot") public void test_pivot(int minWidth, int maxWidth, int baseValue, int value, String result) throws Exception { try { getFormatter0(YEAR, minWidth, maxWidth, baseValue).formatTo(new MockFieldValue(YEAR, value), buf); if (result == null) { fail("Expected exception"); } assertEquals(buf.toString(), result); } catch (DateTimeException ex) { if (result == null || value < 0) { assertEquals(ex.getMessage().contains(YEAR.toString()), true); } else { throw ex; } } }
Example #12
Source File: TestReducedPrinter.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
@Test(dataProvider="Pivot") public void test_pivot_baseDate(int minWidth, int maxWidth, int baseValue, int value, String result) throws Exception { try { getFormatterBaseDate(YEAR, minWidth, maxWidth, baseValue).formatTo(new MockFieldValue(YEAR, value), buf); if (result == null) { fail("Expected exception"); } assertEquals(buf.toString(), result); } catch (DateTimeException ex) { if (result == null || value < 0) { assertEquals(ex.getMessage().contains(YEAR.toString()), true); } else { throw ex; } } }
Example #13
Source File: HijrahChronology.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Return the epoch day computed from Hijrah year, month, and day. * * @param prolepticYear the year to represent, 0-origin * @param monthOfYear the month-of-year to represent, 1-origin * @param dayOfMonth the day-of-month to represent, 1-origin * @return the epoch day */ long getEpochDay(int prolepticYear, int monthOfYear, int dayOfMonth) { checkCalendarInit(); // ensure that the chronology is initialized checkValidMonth(monthOfYear); int epochMonth = yearToEpochMonth(prolepticYear) + (monthOfYear - 1); if (epochMonth < 0 || epochMonth >= hijrahEpochMonthStartDays.length) { throw new DateTimeException("Invalid Hijrah date, year: " + prolepticYear + ", month: " + monthOfYear); } if (dayOfMonth < 1 || dayOfMonth > getMonthLength(prolepticYear, monthOfYear)) { throw new DateTimeException("Invalid Hijrah day of month: " + dayOfMonth); } return epochMonthToEpochDay(epochMonth) + (dayOfMonth - 1); }
Example #14
Source File: AbstractChronology.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
ChronoLocalDate resolveYAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) { int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR); if (resolverStyle == ResolverStyle.LENIENT) { long weeks = Math.subtractExact(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), 1); long days = Math.subtractExact(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), 1); return dateYearDay(y, 1).plus(weeks, WEEKS).plus(days, DAYS); } int aw = range(ALIGNED_WEEK_OF_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_WEEK_OF_YEAR), ALIGNED_WEEK_OF_YEAR); int ad = range(ALIGNED_DAY_OF_WEEK_IN_YEAR).checkValidIntValue(fieldValues.remove(ALIGNED_DAY_OF_WEEK_IN_YEAR), ALIGNED_DAY_OF_WEEK_IN_YEAR); ChronoLocalDate date = dateYearDay(y, 1).plus((aw - 1) * 7 + (ad - 1), DAYS); if (resolverStyle == ResolverStyle.STRICT && date.get(YEAR) != y) { throw new DateTimeException("Strict mode rejected resolved date as it is in a different year"); } return date; }
Example #15
Source File: Parsed.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private void updateCheckConflict(ChronoLocalDate cld) { if (date != null) { if (cld != null && date.equals(cld) == false) { throw new DateTimeException("Conflict found: Fields resolved to two different dates: " + date + " " + cld); } } else if (cld != null) { if (chrono.equals(cld.getChronology()) == false) { throw new DateTimeException("ChronoLocalDate must use the effective parsed chronology: " + chrono); } date = cld; } }
Example #16
Source File: TCKSignStyle.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="signStyle") Object[][] data_signStyle() { return new Object[][] { {LocalDate.of(0, 10, 2), SignStyle.ALWAYS, null, "+00"}, {LocalDate.of(2001, 10, 2), SignStyle.ALWAYS, null, "+2001"}, {LocalDate.of(-2001, 10, 2), SignStyle.ALWAYS, null, "-2001"}, {LocalDate.of(2001, 10, 2), SignStyle.NORMAL, null, "2001"}, {LocalDate.of(-2001, 10, 2), SignStyle.NORMAL, null, "-2001"}, {LocalDate.of(2001, 10, 2), SignStyle.NEVER, null, "2001"}, {LocalDate.of(-2001, 10, 2), SignStyle.NEVER, null, "2001"}, {LocalDate.of(2001, 10, 2), SignStyle.NOT_NEGATIVE, null, "2001"}, {LocalDate.of(-2001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""}, {LocalDate.of(0, 10, 2), SignStyle.EXCEEDS_PAD, null, "00"}, {LocalDate.of(1, 10, 2), SignStyle.EXCEEDS_PAD, null, "01"}, {LocalDate.of(-1, 10, 2), SignStyle.EXCEEDS_PAD, null, "-01"}, {LocalDate.of(20001, 10, 2), SignStyle.ALWAYS, DateTimeException.class, ""}, {LocalDate.of(20001, 10, 2), SignStyle.NORMAL, DateTimeException.class, ""}, {LocalDate.of(20001, 10, 2), SignStyle.NEVER, DateTimeException.class, ""}, {LocalDate.of(20001, 10, 2), SignStyle.EXCEEDS_PAD, DateTimeException.class, ""}, {LocalDate.of(20001, 10, 2), SignStyle.NOT_NEGATIVE, DateTimeException.class, ""}, }; }
Example #17
Source File: TCKInstant.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@DataProvider(name="with_longTemporalField") Object[][] data_with_longTemporalField() { return new Object[][]{ {Instant.ofEpochSecond(10, 200), ChronoField.INSTANT_SECONDS, 100, Instant.ofEpochSecond(100, 200), null}, {Instant.ofEpochSecond(10, 200), ChronoField.INSTANT_SECONDS, 0, Instant.ofEpochSecond(0, 200), null}, {Instant.ofEpochSecond(10, 200), ChronoField.INSTANT_SECONDS, -100, Instant.ofEpochSecond(-100, 200), null}, {Instant.ofEpochSecond(10, 200), ChronoField.NANO_OF_SECOND, 100, Instant.ofEpochSecond(10, 100), null}, {Instant.ofEpochSecond(10, 200), ChronoField.NANO_OF_SECOND, 0, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10, 200), ChronoField.MICRO_OF_SECOND, 100, Instant.ofEpochSecond(10, 100*1000), null}, {Instant.ofEpochSecond(10, 200), ChronoField.MICRO_OF_SECOND, 0, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10, 200), ChronoField.MILLI_OF_SECOND, 100, Instant.ofEpochSecond(10, 100*1000*1000), null}, {Instant.ofEpochSecond(10, 200), ChronoField.MILLI_OF_SECOND, 0, Instant.ofEpochSecond(10), null}, {Instant.ofEpochSecond(10, 200), ChronoField.NANO_OF_SECOND, 1000000000L, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.MICRO_OF_SECOND, 1000000, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.MILLI_OF_SECOND, 1000, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.SECOND_OF_MINUTE, 1, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.SECOND_OF_DAY, 1, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.OFFSET_SECONDS, 1, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.NANO_OF_DAY, 1, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.MINUTE_OF_HOUR, 1, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.MINUTE_OF_DAY, 1, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.MILLI_OF_DAY, 1, null, DateTimeException.class}, {Instant.ofEpochSecond(10, 200), ChronoField.MICRO_OF_DAY, 1, null, DateTimeException.class}, }; }
Example #18
Source File: DateTimePrintContext.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Gets the value of the specified field. * <p> * This will return the value for the specified field. * * @param field the field to find, not null * @return the value, null if not found and optional is true * @throws DateTimeException if the field is not available and the section is not optional */ Long getValue(TemporalField field) { try { return temporal.getLong(field); } catch (DateTimeException ex) { if (optional > 0) { return null; } throw ex; } }
Example #19
Source File: TestDateTimeFormatter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
private void assertGoodErrorDate(Function<TemporalAccessor, Object> function, String expectedText) { DateTimeFormatter f = DateTimeFormatter.ofPattern("yyyy-mm-dd"); TemporalAccessor temporal = f.parse("2010-06-30"); try { function.apply(temporal); fail("Should have failed"); } catch (DateTimeException ex) { String msg = ex.getMessage(); assertTrue(msg.contains(expectedText), msg); assertTrue(msg.contains("Year"), msg); assertTrue(msg.contains("MinuteOfHour"), msg); assertTrue(msg.contains("DayOfMonth"), msg); } }
Example #20
Source File: TCKLocalTime.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test public void test_plus_longTemporalUnit_invalidUnit() { for (TemporalUnit unit : INVALID_UNITS) { try { TEST_12_30_40_987654321.plus(1, unit); fail("Unit should not be allowed " + unit); } catch (DateTimeException ex) { // expected } } }
Example #21
Source File: TCKLocalDateTime.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_minusDays_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 12, 31).minusDays(-1); }
Example #22
Source File: TCKLocalTime.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_time_3ints_secondTooLow() { LocalTime.of(0, 0, -1); }
Example #23
Source File: TCKZoneOffset.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_factory_int_hours_minutes_seconds_plusHoursMinusMinutes() { ZoneOffset.ofHoursMinutesSeconds(1, -1, 0); }
Example #24
Source File: TCKLocalDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void factory_of_7ints_nanoTooLow() { LocalDateTime.of(2007, 7, 15, 12, 30, 40, -1); }
Example #25
Source File: TCKYearMonth.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_withYear_tooLow() { YearMonth test = YearMonth.of(2008, 6); test.withYear(Year.MIN_VALUE - 1); }
Example #26
Source File: TCKLocalDateTime.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_minusYears_int_invalidTooLarge() { createDateMidnight(Year.MAX_VALUE, 1, 1).minusYears(-1); }
Example #27
Source File: TCKLocalDate.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_atTime_int_int_int_int_hourTooSmall() { LocalDate t = LocalDate.of(2008, 6, 30); t.atTime(-1, 30, 40, 50); }
Example #28
Source File: TCKYearMonth.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_plusYears_long_invalidTooLarge() { YearMonth test = YearMonth.of(Year.MAX_VALUE, 6); test.plusYears(1); }
Example #29
Source File: TCKLocalDate.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_plus_longTemporalUnit_invalidTooLarge() { LocalDate.of(Year.MAX_VALUE, 1, 1).plus(1, ChronoUnit.YEARS); }
Example #30
Source File: TCKLocalDate.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void test_withDayOfMonth_invalid() { LocalDate.of(2007, 11, 30).withDayOfMonth(31); }