### Question:
DateUtils { public String format(Date date) { int diffInDays = diffInDaysFromNow(date); if (diffInDays < SEVEN_DAYS) { return formatInDays(diffInDays); } else { return formatInWeeks(diffInDays); } } @Inject  DateUtils(TranslationService translationService); String format(Date date); static final int ONE_DAY_IN_MS; }### Answer:
@Test public void testFormatToday() { String expected = "today"; when(translationService.getTranslation(LibraryConstants.Today)).thenReturn(expected); String actual = dateUtils.format(new Date()); assertEquals(expected, actual); }
@Test public void testFormatOneDayAgo() { String expected = "1 day ago"; int nDays = 1; when(translationService.getTranslation(LibraryConstants.OneDayAgo)).thenReturn(expected); String actual = dateUtils.format(createDateFromNow(nDays)); assertEquals(expected, actual); }
@Test public void testFormatTwoDaysAgo() { String expected = "2 days ago"; int nDays = 2; when(translationService.format(LibraryConstants.DaysAgo, nDays)).thenReturn(expected); String actual = dateUtils.format(createDateFromNow(nDays)); assertEquals(expected, actual); }
@Test public void testFormatOneWeekAgoWithSevenDays() { String expected = "1 week ago"; int nDays = 7; when(translationService.getTranslation(LibraryConstants.OneWeekAgo)).thenReturn(expected); String actual = dateUtils.format(createDateFromNow(nDays)); assertEquals(expected, actual); }
@Test public void testFormatOneWeekAgoWithEightDays() { String expected = "1 week ago"; int nDays = 8; when(translationService.getTranslation(LibraryConstants.OneWeekAgo)).thenReturn(expected); String actual = dateUtils.format(createDateFromNow(nDays)); assertEquals(expected, actual); }
@Test public void testFormatTwoWeeksAgoWithFourteenDays() { String expected = "2 weeks ago"; int nDays = 14; int nWeeks = 2; when(translationService.format(LibraryConstants.WeeksAgo, nWeeks)).thenReturn(expected); String actual = dateUtils.format(createDateFromNow(nDays)); assertEquals(expected, actual); }
@Test public void testFormatTwoWeeksAgoWithFifteenDays() { String expected = "2 weeks ago"; int nDays = 15; int nWeeks = 2; when(translationService.format(LibraryConstants.WeeksAgo, nWeeks)).thenReturn(expected); String actual = dateUtils.format(createDateFromNow(nDays)); assertEquals(expected, actual); }