DateTools { public String dateToString(@Nullable final Date date, final String format) { return Tools.dateToString(date, format); }  String currentDateToString(final String format); String dateToString(@Nullable final Date date, final String format); String howLongFromNow(final long then);  }
@Test public void dateToStringShouldConvertSpecifiedDateToStringWithCorrectFormat() { final Date date = new DateTime().withDate(2014, 5, 13).withTime(23, 52, 28, 0).toDate(); final String dateAsString = dateTools.dateToString(date, "dd.MM.yyyy HH:mm:ss"); assertEquals("13.05.2014 23:52:28", dateAsString); }
@Test public void dateToStringShouldUseTodayWhenDateIsNull() { final String dateAsString = dateTools.dateToString(null, "yyyy"); assertEquals(String.valueOf(new DateTime().getYear()), dateAsString); }