DateUtil { public static Date fromISO8601(String pDateString) { if (datatypeFactory != null) { return datatypeFactory.newXMLGregorianCalendar(pDateString.trim()).toGregorianCalendar().getTime(); } else { try { String date = pDateString.replaceFirst("([+-])(0\\d)\\:(\\d{2})$", "$1$2$3"); date = date.replaceFirst("Z$","+0000"); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); return dateFormat.parse(date); } catch (ParseException e) { throw new IllegalArgumentException("Cannot parse date '" + pDateString + "': " +e,e); } } } private  DateUtil(); static Date fromISO8601(String pDateString); static String toISO8601(Date pDate); static String toISO8601(Date pDate,TimeZone pTimeZone);  }
@Test(expectedExceptions = {IllegalArgumentException.class}) public void illegalFormat() { DateUtil.fromISO8601("Bla"); }
@Test(expectedExceptions = {IllegalArgumentException.class}) public void illegalFormat2() throws NoSuchFieldException, IllegalAccessException { Object oldValue = exchangeDataTypeFactory(); DateUtil.fromISO8601("Bla"); resetDataTypeFactory(oldValue); }