HerdDateUtils extends DateUtils { public static String formatDuration(long duration) { StringBuilder result = new StringBuilder(); long remainingDuration = duration; if (remainingDuration == 0) { result.append("0 Milliseconds"); } else { remainingDuration = processDuration(remainingDuration, MILLIS_PER_DAY, "Day", result, false); remainingDuration = processDuration(remainingDuration, MILLIS_PER_HOUR, "Hour", result, false); remainingDuration = processDuration(remainingDuration, MILLIS_PER_MINUTE, "Minute", result, false); remainingDuration = processDuration(remainingDuration, MILLIS_PER_SECOND, "Second", result, false); long milliSeconds = remainingDuration; if (milliSeconds > 0) { processDuration(remainingDuration, 1, "Millisecond", result, true); } } return result.toString(); }  static Calendar getCurrentCalendarNoTime(); static String formatDuration(long duration); static XMLGregorianCalendar now(); static XMLGregorianCalendar getXMLGregorianCalendarValue(Date date); static Timestamp addDays(Timestamp timestamp, int amount); static Timestamp addMinutes(Timestamp timestamp, int amount); static Timestamp resetTimeToMidnight(XMLGregorianCalendar xmlGregorianCalendar); static Timestamp convertToTimestamp(XMLGregorianCalendar xmlGregorianCalendar); static Boolean containsTimePortion(XMLGregorianCalendar xmlGregorianCalendar);  }
@Test public void testFormatDurationZeroMilliseconds() { String result = HerdDateUtils.formatDuration(0); assertEquals("0 Milliseconds", result); }
@Test public void testFormatDurationDays() { int length = 100; String result = HerdDateUtils.formatDuration(MILLIS_PER_DAY * length); assertEquals(length + " Days", result); }
@Test public void testFormatDurationHours() { String result = HerdDateUtils.formatDuration(MILLIS_PER_HOUR); assertEquals("1 Hour", result); }
@Test public void testFormatDurationMinutes() { String result = HerdDateUtils.formatDuration(MILLIS_PER_MINUTE); assertEquals("1 Minute", result); }
@Test public void testFormatDurationSeconds() { String result = HerdDateUtils.formatDuration(MILLIS_PER_SECOND); assertEquals("1 Second", result); }
@Test public void testFormatDurationMilliseconds() { String result = HerdDateUtils.formatDuration(1); assertEquals("1 Millisecond", result); int length = 999; result = HerdDateUtils.formatDuration(length); assertEquals(length + " Milliseconds", result); }
@Test public void testFormatDurationMultipleUnits() { long millis = 300; long seconds = 2; long minutes = 59; long hours = 23; long days = 999; long duration = millis + MILLIS_PER_SECOND * seconds + MILLIS_PER_MINUTE * minutes + MILLIS_PER_HOUR * hours + MILLIS_PER_DAY * days; String expectedResult = days + " Days, " + hours + " Hours, " + minutes + " Minutes, " + seconds + " Seconds, " + millis + " Milliseconds"; String result = HerdDateUtils.formatDuration(duration); assertEquals(expectedResult, result); }