DateRange { @Override public String toString() { return String.format("DateRange [%s - %s]", (this.startDate != null ? String.format(DATE_FORMAT, this.startDate) : null), (this.endDate != null ? String.format(DATE_FORMAT, this.endDate) : null)); } DateRange();  DateRange(Date start, Date end); void setStartDate(Date start); void setEndDate(Date end); Date getStartDate(); Date getEndDate(); boolean contains(Date date); @Override String toString();  }
@Test public void string() { DateRange range = new DateRange(TestDateUtil.date(2012, 5, 22), TestDateUtil.date(2013, 7, 4)); String result = range.toString(); String dateFormat = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}[-+]\\d{4}"; String expectedRegex = String.format("DateRange \\[%1$s - %1$s\\]", dateFormat); assertTrue(String.format("\"%s\" did not match the expected format: %s", result, expectedRegex), result.matches(expectedRegex)); }