DateRange { @Override public String toString() { String startString = startDate != null ? DATE_FORMAT.format(startDate) : "null"; String stopString = stopDate != null ? DATE_FORMAT.format(stopDate) : "null"; return OPENING_BRACKET + startString + SEPARATOR + stopString + CLOSING_BRACKET; } DateRange(Date startDate, Date stopDate); Date getStartDate(); Date getStopDate(); @Override String toString(); static DateRange parseDateRange(String dateRange); static final DateRange OPEN_RANGE; static final DateFormat DATE_FORMAT; }
@Test public void testToString() throws Exception { DateFormat dateFormat = DateRange.DATE_FORMAT; Date minDate = dateFormat.parse("1245-04-22"); Date maxDate = dateFormat.parse("1245-04-23"); DateRange dateRange = new DateRange(minDate, maxDate); assertEquals("[1245-04-22:1245-04-23]", dateRange.toString()); }
@Test public void testToStringWithNull() throws Exception { assertEquals("[null:null]", DateRange.OPEN_RANGE.toString()); }