ValidationRuleExpirationDate extends AbstractValidationRule { Date obtainEnteredDateFromUnmaskedValue(String text) throws ParseException { DateFormat fieldDateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN_MONTH_YEAR); DateFormat centuryDateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN_CENTURY); fieldDateFormat.setLenient(false); Date now = new Date(); String year = centuryDateFormat.format(now); String textWithCentury = text.substring(0, 2) + year.substring(0, 2) + text.substring(2, 4); return fieldDateFormat.parse(textWithCentury); } ValidationRuleExpirationDate(String errorMessage, ValidationType type); @Override @Deprecated boolean validate(String text); @Override boolean validate(PaymentRequest paymentRequest, String fieldId);  }
@Test public void testObtainDateNormal() throws ParseException { Date toBeValidated = testValidationRule.obtainEnteredDateFromUnmaskedValue("0311"); Calendar calendar = Calendar.getInstance(); calendar.clear(); calendar.setTime(toBeValidated); assertEquals(Calendar.MARCH, calendar.get(Calendar.MONTH)); assertEquals(2011, calendar.get(Calendar.YEAR)); }