### Question:
DateUtil { public static Date stringToDate(String strDate,SimpleDateFormat customTimeFormat) { if(strDate == null || strDate.trim().length() == 0) { return null; } if(customTimeFormat != null){ try { return customTimeFormat.parse(strDate); } catch (ParseException ignored) { } } try { return datetimeFormatter.get().get(STANDARD_DATETIME_FORMAT).parse(strDate); } catch (ParseException ignored) { } try { return datetimeFormatter.get().get(UN_STANDARD_DATETIME_FORMAT).parse(strDate); } catch (ParseException ignored) { } try { return datetimeFormatter.get().get(DATE_FORMAT).parse(strDate); } catch (ParseException ignored) { } try { return datetimeFormatter.get().get(TIME_FORMAT).parse(strDate); } catch (ParseException ignored) { } try { return datetimeFormatter.get().get(YEAR_FORMAT).parse(strDate); } catch (ParseException ignored) { } throw new RuntimeException("can't parse date"); } private  DateUtil(); static java.sql.Date columnToDate(Object column,SimpleDateFormat customTimeFormat); static java.sql.Timestamp columnToTimestamp(Object column,SimpleDateFormat customTimeFormat); static long getMillSecond(String data); static Date stringToDate(String strDate,SimpleDateFormat customTimeFormat); static String dateToString(Date date); static String timestampToString(Date date); static String dateToYearString(Date date); static SimpleDateFormat getDateTimeFormatter(); static SimpleDateFormat getDateFormatter(); static SimpleDateFormat getTimeFormatter(); static SimpleDateFormat getYearFormatter(); static SimpleDateFormat buildDateFormatter(String timeFormat); final static String DATE_REGEX; final static String TIMESTAMP_REGEX; final static String DATETIME_REGEX; final static int LENGTH_SECOND; final static int LENGTH_MILLISECOND; final static int LENGTH_MICROSECOND; final static int LENGTH_NANOSECOND; static ThreadLocal<Map<String,SimpleDateFormat>> datetimeFormatter; }### Answer:
@Test public void testStringToDate() { java.util.Date result = DateUtil.stringToDate("", null); Assert.assertNull(result); result = DateUtil.stringToDate("2020/03/18 13:26:00", new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")); Assert.assertEquals(result, new java.util.Date(1584509160000L)); try { DateUtil.stringToDate("xxxx", null); } catch (Exception e) { Assert.assertTrue(e.getMessage().contains("can't parse date")); } }