DateUtils { public static Date parseDate(final String format, final String dateString) { try { final SimpleDateFormat sdf = new SimpleDateFormat(format); sdf.setLenient(false); return sdf.parse(dateString); } catch (ParseException e) { throw new IllegalArgumentException("Unable to parse date " + dateString + " (format:" + format + ")", e); } } private  DateUtils(); static Date parseDate(final String format, final String dateString); static final String DEFAULT_DATE_FORMAT; }
@Test public void test( ) { assertNotNull(DateUtils.parseDate(DateUtils.DEFAULT_DATE_FORMAT, "2020-02-22")); }
@Test public void testException() { assertThrows(IllegalArgumentException.class, () -> DateUtils.parseDate(DateUtils.DEFAULT_DATE_FORMAT, "20-2020-02")); }