### Question:
Convert { public static Date toDate(String dateString) { Date dateConverted = null; if (StringUtils.isNotBlank(dateString)) { try { if (StringUtils.isNumeric(dateString)) { dateConverted = new Date(Long.parseLong(dateString)); } else { String formats[] = { "MM/dd/yyyy HH:mm:ss z ", "yyyy-mm-dd HH:mm:ss z ", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "dd MMM yyyy hh:mm:ss a z", "MM/dd/yyyy", "yyyy-mm-dd", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z", "EEE, d MMM yyyy HH:mm:ss Z" }; for (String format : formats) { SimpleDateFormat sdf = new SimpleDateFormat(format); dateConverted = sdf.parse(dateString, new ParsePosition(0)); if (dateConverted != null) { break; } } } } catch (Exception e) { dateConverted = null; } } return dateConverted; } private  Convert(); static boolean toBoolean(Object data); static Integer toInteger(Object data); static Long toLong(Object data); static BigDecimal toBigDecimal(Object data); static BigDecimal toBigDecimal(Object data, BigDecimal defaultDecimal); static Date toDate(String dateString);  }### Answer:
@Test public void testToDate() { System.out.println("toDate"); String dateString = ""; Date expResult = null; Date result = Convert.toDate(dateString); List<String> validDates = Arrays.asList("07/04/2016 12:00:01 PST ", "1999-05-10 08:30:44 MST ", "1997-04-30T12:08:56.235-0700", "01 Jul 2016 11:33:54 PM PST","12/25/2003","2001-08-12", "1997-04-30T12:08:56.235'-0700"); List<String> partiallyValidDates = Arrays.asList("13/12/202 25:00: AFFAT", "1997-04-3012:08:56235-0700", "01 January 01 11:33:54 PM PST", "122519803543"); List<String> invalidDates = Arrays.asList("", "null", "thisis1test", "D", "12.344.555"); for (String testDate : validDates) { result = Convert.toDate(testDate); if(result == null) { fail("Incorrect date format: " + testDate); } } for (String testDate : partiallyValidDates) { result = Convert.toDate(testDate); if(result == null) { fail("Incorrect date format: " + testDate); } else { System.out.println("Given date: " + testDate + " vs parsed date " + result); } } for (String testDate : invalidDates) { result = Convert.toDate(testDate); assertEquals(expResult, result); } }