MultiFormatDateParser { static public Date parse(String dateString) { for (Rule candidate : rules) { if (candidate.pattern.matcher(dateString).matches()) { Date result; try { synchronized(candidate.format) { result = candidate.format.parse(dateString); } } catch (ParseException ex) { log.info("Date string '{}' matched pattern '{}' but did not parse: {}", new String[] {dateString, candidate.format.toPattern(), ex.getMessage()}); continue; } return result; } } return null; }  @Inject void setPatterns(Map<String, String> patterns); static Date parse(String dateString); static void main(String[] args);  }
@Test public void testParse() throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(expectedFormat); simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Date result = MultiFormatDateParser.parse(toParseDate); assertEquals(testMessage, expectedResult, simpleDateFormat.parse(toParseDate).equals(result)); }