DateAdapter { static Date parseDate(String dateToParse) { try { return TEAMCITY_DATE_FORMAT.parse(dateToParse); } catch (ParseException e) { throw new IllegalArgumentException(e); } } private  DateAdapter();   }
@Test public void should_parse_date() { Date date = DateAdapter.parseDate("20110302T171940+0300"); Calendar cal = Calendar.getInstance(); cal.setTime(date); assertEquals(2011, cal.get(Calendar.YEAR)); assertEquals(2, cal.get(Calendar.DAY_OF_MONTH)); assertEquals(3, cal.get(Calendar.MONTH) + 1); assertTrue(15 == cal.get(Calendar.HOUR_OF_DAY) || 9 == cal.get(Calendar.HOUR_OF_DAY)); assertEquals(19, cal.get(Calendar.MINUTE)); assertEquals(40, cal.get(Calendar.SECOND)); }
@Test(expected = NullPointerException.class) public void cant_pass_null_as_parameter() { DateAdapter.parseDate(null); }
@Test(expected = IllegalArgumentException.class) public void should_throw_exception_when_parameter_is_not_a_date() { DateAdapter.parseDate("not_a_date"); }