DateHeaderDelegate implements RuntimeDelegate.HeaderDelegate<Date> { @Override public Date fromString(String header) { if (header == null) { throw new IllegalArgumentException(); } return HeaderHelper.parseDateHeader(header); }  @Override Date fromString(String header); @Override String toString(Date date);  }
@Test public void parsesANSI() { String dateHeader = "THU DEC 29 12:03:50 2011"; Date expectedDate = date(2011, 12, 29, 12, 3, 50, "GMT"); Date date = dateHeaderDelegate.fromString(dateHeader); assertTrue(String.format("Dates are not equal. Expected %s, actual %s", expectedDate, date), Math.abs(expectedDate.getTime() - date.getTime()) < 1000); }
@Test public void parsesRFC_1036() { String dateHeader = "Thursday, 29-Dec-11 12:03:50 EST"; Date expectedDate = date(2011, 12, 29, 12, 3, 50, "EST"); Date date = dateHeaderDelegate.fromString(dateHeader); assertTrue(String.format("Dates are not equal, %s and %s", expectedDate, date), Math.abs(expectedDate.getTime() - date.getTime()) < 1000); }
@Test public void parsesRFC_1123() { String dateHeader = "Thu, 29 Dec 2011 12:03:50 GMT"; Date expectedDate = date(2011, 12, 29, 12, 3, 50, "GMT"); Date date = dateHeaderDelegate.fromString(dateHeader); assertTrue(String.format("Dates are not equal, %s and %s", expectedDate, date), Math.abs(expectedDate.getTime() - date.getTime()) < 1000); }
@Test(expected = IllegalArgumentException.class) public void failsParseDateIfItDoesNotMatchToAnySupportedFormat() { String dateHeader = "12:03:50 GMT"; dateHeaderDelegate.fromString(dateHeader); }
@Test(expected = IllegalArgumentException.class) public void throwsExceptionWhenHeaderIsNull() throws Exception { dateHeaderDelegate.fromString(null); }