### Question:
DateUtil { public static Date getDateFromString(String strDate) throws DateException { int length = strDate.length(); if(length == 6) { return getDateFromString(strDate, "yyMMdd"); } if(length == 8) { return getDateFromString(strDate, "yyyyMMdd"); } if(length == 10) { return getDateFromString(strDate, "yyyy-MM-dd"); } return getDateFromString(strDate, "yy-MM-dd"); }  static Date getEndDate(Date date, int amount); static Date getEndDate(Date date); static Date getStartDate(Date date, int amount); static Date getStartDate(Date date); static Date getDateFromString(String strDate); static Date getDateFromString(String strDate, String format); static String getFormat2FromStd(String date, String format); static String getFormat2FromFormat1(String date, String format1, String format2); static String getStringFromDate(Date dt); static String getStringFromDate(Date dt, String format); static int diffDate(Date dt1, Date dt2); static String getDistanceTime(String one, String two, String format); static String getDistanceTime( Date one, Date two); static int getDistanceDay(Date d1, Date d2); static int diffDate(String dt1, String dt2); static int diffDate(String dt1, String dt2, String format); static Date addDaysToDate(Date dt1, int days); static Date addHoursToDate(Date date, int hours); static Date addDaysToDate(String dt1, int days); static Date addDaysToDate(String dt1, String format, int days); static String getCurrentDate(); static String getCurrentTime(); static String getCurrentDateTime(); static String getCurrentDateTime(String format); static String getCurrentDateTime(long currentTimeMillis, String format); static String getUTCdatetimeAsString(Date date,String format); static Date getUTCdatetimeAsDate(Date date,String format); static boolean isSameDayOfWeek(Date date1, Date date2); static boolean isSameDayOfWeek(Calendar cal1, Calendar cal2); static boolean isSameDayOfMonth(Date date1, Date date2); static boolean isSameDayOfMonth(Calendar cal1, Calendar cal2); static boolean isSameMonth(Calendar cal1, Calendar cal2); static Date add(Date date, int calendarField, int amount);  }### Answer:
@Test public void testGetDateFromString() { Calendar c = Calendar.getInstance(); Date date = DateUtil.getDateFromString("170712"); c.setTime(date); assertEquals(2017, c.get(Calendar.YEAR)); assertEquals(6, c.get(Calendar.MONTH)); assertEquals(12, c.get(Calendar.DAY_OF_MONTH)); date = DateUtil.getDateFromString("20160314"); c.setTime(date); assertEquals(2016, c.get(Calendar.YEAR)); assertEquals(2, c.get(Calendar.MONTH)); assertEquals(14, c.get(Calendar.DAY_OF_MONTH)); date = DateUtil.getDateFromString("2015-05-16"); c.setTime(date); assertEquals(2015, c.get(Calendar.YEAR)); assertEquals(4, c.get(Calendar.MONTH)); assertEquals(16, c.get(Calendar.DAY_OF_MONTH)); }