public static Changed parse(final String value) { if (value.length() > MAX_LENGTH) { throw new AttributeParseException("Too long", value); } final Matcher matcher = CHANGED_PATTERN.matcher(value); if (!matcher.matches()) { throw new AttributeParseException("Invalid syntax", value); } final String email = matcher.group(1).trim(); final String dateString = matcher.group(2); final LocalDate date; if (dateString == null) { date = null; } else { try { date = CHANGED_ATTRIBUTE_DATE_FORMAT.parseLocalDate(dateString); } catch (IllegalFieldValueException e) { throw new AttributeParseException("Invalid date: " + dateString, value); } } return new Changed(email, date); }
@Test public void getUnderflowDate() throws Exception { try { client.datetimes().getUnderflow(); Assert.assertTrue(false); } catch (Exception exception) { // expected Assert.assertEquals(IllegalFieldValueException.class, exception.getClass()); } }
@Test public void getUnderflowDate() throws Exception { try { client.dates().getUnderflowDate(); Assert.assertTrue(false); } catch (Exception exception) { // expected Assert.assertEquals(IllegalFieldValueException.class, exception.getClass()); } }
@Test(expected=IllegalFieldValueException.class) public void testIssue233JodaTimeLimit() throws ParseException { // https://github.com/aws/aws-sdk-java/issues/233 String s = DateUtils.iso8601DateFormat.print(Long.MAX_VALUE); System.out.println("s: " + s); try { DateTime dt = DateUtils.iso8601DateFormat.parseDateTime(s); fail("Unexpected success: " + dt); } catch(IllegalFieldValueException ex) { // expected throw ex; } }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaAll() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( 0, 0, 0, 0, 0 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaDayHourMinute() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( 1, 1, -1, -1, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaHourMinute() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( 1, 1, 1, -1, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaMinute() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( 1, 1, 1, 1, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaMonthDayHourMinute() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( 1, -1, -1, -1, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaYear() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( -1, 0, 0, 0, 0 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaYearMonth() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( -1, -1, 0, 0, 0 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaYearMonthDay() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( -1, -1, -1, 0, 0 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaYearMonthDayHour() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( -1, -1, -1, -1, 0 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDateHourFalhaYearMonthDayHourMinute() { // Fixture Setup, DateTime(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour) // Exercise SUT final DateTime DateHour = new DateTime( -1, -1, -1, -1, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDeDateFalhaDayNegative() { // Fixture Setup // Exercise SUT final LocalDate natal2017 = new LocalDate( 2017, 12, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDeDateFalhaMonthDayNegative() { // Fixture Setup // Exercise SUT final LocalDate natal2017 = new LocalDate( 0, -1, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDeDateFalhaMonthNegative() { // Fixture Setup // Exercise SUT final LocalDate natal2017 = new LocalDate( 2017, -1, 1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDeDateFalhaYearMontDayNegative() { // Fixture Setup // Exercise SUT final LocalDate natal2017 = new LocalDate( -1, -1, -1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDeDateFalhaYearMonthNegative() { // Fixture Setup // Exercise SUT final LocalDate natal2017 = new LocalDate( -1, -1, 1 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDeDateFalhaYearNegative() { // Fixture Setup // Exercise SUT final LocalDate natal2017 = new LocalDate( -20, 1, 0 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void creationDeHoursFalha() { // Fixture Setup // Exercise SUT final LocalTime HourAtual = new LocalTime( -12, 12, 25 ); // Result Verification // Fixture Teardown }
@Test( expected = IllegalFieldValueException.class ) public void criaDateFalhaDeAnoBissextoInvalido() { // Fixture Setup // Exercise SUT final LocalDate dia29Fevereiro = new LocalDate( 2017, 2, 29 ); // Result Verification // Fixture Teardown }
@Override public long set(long instant, int value) { // Check for illegal values: this is not a lenient field if (value < 1 || value > this.numMonthsInYear) { throw new IllegalFieldValueException(this.getType(), value, 1, this.numMonthsInYear); } // What is the current month? int monthOfYear = this.get(instant); // How many months do we have to add to arrive at the new value int monthsToAdd = value - monthOfYear; // Now add the required number of months return this.add(instant, monthsToAdd); }
@Test(expectedExceptions = IllegalFieldValueException.class) public void testDetermineLogStartIllegalField() throws Exception { LogFileParser parser = getParserWithoutLogStart(); Pattern pattern = LogFileParser.LOGSTART_PATTERN; String logFileOpenRow = "Log: Log file open, 09/24/15 219:34:25"; Matcher matcher = pattern.matcher(logFileOpenRow); assertTrue(matcher.matches()); assertNull(parser.getLogStart()); parser.determineLogStart(matcher); }
/** * Verify that input values are within specified bounds. * * @param value the value to check * @param lowerBound the lower bound allowed for value * @param upperBound the upper bound allowed for value * @throws IllegalFieldValueException if value is not in the specified bounds */ public static void verifyValueBounds(DateTimeField field, int value, int lowerBound, int upperBound) { if ((value < lowerBound) || (value > upperBound)) { throw new IllegalFieldValueException (field.getType(), Integer.valueOf(value), Integer.valueOf(lowerBound), Integer.valueOf(upperBound)); } }
/** * Verify that input values are within specified bounds. * * @param value the value to check * @param lowerBound the lower bound allowed for value * @param upperBound the upper bound allowed for value * @throws IllegalFieldValueException if value is not in the specified bounds */ public static void verifyValueBounds(String fieldName, int value, int lowerBound, int upperBound) { if ((value < lowerBound) || (value > upperBound)) { throw new IllegalFieldValueException (fieldName, Integer.valueOf(value), Integer.valueOf(lowerBound), Integer.valueOf(upperBound)); } }
public long set(long millis, int value) { FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue()); if (value <= iSkip) { if (value == iSkip) { throw new IllegalFieldValueException (DateTimeFieldType.year(), Integer.valueOf(value), null, null); } value++; } return super.set(millis, value); }
/** @inheritDoc */ public long set(long instant, String text, Locale locale) { if (iEraText.equals(text) == false && "1".equals(text) == false) { throw new IllegalFieldValueException(DateTimeFieldType.era(), text); } return instant; }
public long set(long instant, int value) { long localInstant = iZone.convertUTCToLocal(instant); localInstant = iField.set(localInstant, value); long result = iZone.convertLocalToUTC(localInstant, false, instant); if (get(result) != value) { throw new IllegalFieldValueException(iField.getType(), Integer.valueOf(value), "Illegal instant due to time zone offset transition: " + DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").print(new Instant(localInstant)) + " (" + iZone.getID() + ")"); } return result; }
static int adjustYearForSet(int year) { if (year <= 0) { if (year == 0) { throw new IllegalFieldValueException (DateTimeFieldType.year(), Integer.valueOf(year), null, null); } year++; } return year; }
public int eraTextToValue(String text) { Integer era = iParseEras.get(text); if (era != null) { return era.intValue(); } throw new IllegalFieldValueException(DateTimeFieldType.era(), text); }
public int monthOfYearTextToValue(String text) { Integer month = iParseMonths.get(text); if (month != null) { return month.intValue(); } throw new IllegalFieldValueException(DateTimeFieldType.monthOfYear(), text); }
public int dayOfWeekTextToValue(String text) { Integer day = iParseDaysOfWeek.get(text); if (day != null) { return day.intValue(); } throw new IllegalFieldValueException(DateTimeFieldType.dayOfWeek(), text); }
public int halfdayTextToValue(String text) { String[] halfday = iHalfday; for (int i = halfday.length; --i>=0; ) { if (halfday[i].equalsIgnoreCase(text)) { return i; } } throw new IllegalFieldValueException(DateTimeFieldType.halfdayOfDay(), text); }
public long set(long instant, int value) { if (instant >= iCutover) { instant = iGregorianField.set(instant, value); if (instant < iCutover) { // Only adjust if gap fully crossed. if (instant + iGapDuration < iCutover) { instant = gregorianToJulian(instant); } // Verify that new value stuck. if (get(instant) != value) { throw new IllegalFieldValueException (iGregorianField.getType(), Integer.valueOf(value), null, null); } } } else { instant = iJulianField.set(instant, value); if (instant >= iCutover) { // Only adjust if gap fully crossed. if (instant - iGapDuration >= iCutover) { instant = julianToGregorian(instant); } // Verify that new value stuck. if (get(instant) != value) { throw new IllegalFieldValueException (iJulianField.getType(), Integer.valueOf(value), null, null); } } } return instant; }
@Override public void validate(Object target, Errors errors) { TourForm form = (TourForm) target; try { new DateTime(form.getDepYear(), form.getDepMonth(), form.getDepDay(), 0, 0).toDate(); } catch (IllegalFieldValueException e) { errors.rejectValue("depYear", "IncorrectDate.inputdate", "Incorrect date was entered."); } }