DurationHelper { public static String createDurationValue(Date startTime, Date endTime) { final Date current = new Date(); if (startTime == null) { startTime = current; log.info("startTime was null, set to current date"); } if (endTime == null) { endTime = current; log.info("endTime was null, set to current date"); } final Long duration = endTime.getTime() - startTime.getTime() < 0 ? 0 : endTime.getTime() - startTime.getTime(); return format(new Date(duration)); } private  DurationHelper(); static String createDurationValue(Date startTime, Date endTime);  }
@Test public void createDurationValueMillisTest() { final String expected = "123 ms"; final Long duration = 123L; final Date startTime = new Date(0); final Date endTime = new Date(duration); final String durationValue = DurationHelper.createDurationValue(startTime, endTime); assertThat(durationValue).isEqualTo(expected); }
@Test public void createDurationValueSecondsMillisTest() { final Long duration = 1024L; final String expectedValue = "01:024 sec"; final Date startTime = new Date(0); final Date endTime = new Date(duration); final String durationValue = DurationHelper.createDurationValue(startTime, endTime); assertThat(durationValue).isEqualTo(expectedValue); }
@Test public void createDurationValueMinutesSecondsMillisTest() { final Long duration = 3400199L; final String expectedValue = "56:40:199 min"; final Date startTime = new Date(0); final Date endTime = new Date(duration); final String durationValue = DurationHelper.createDurationValue(startTime, endTime); assertThat(durationValue).isEqualTo(expectedValue); }
@Test public void createDurationValueHoursMinutesSecondsMillisTest() { final Long duration = 5000199L; final Date startTime = new Date(0); final Date endTime = new Date(duration); final String durationValue = DurationHelper.createDurationValue(startTime, endTime); assertThat(durationValue).isNotNull(); }
@Test public void createDurationValueStarTimeAndEndTimeNullTest() { final String expectedValue = "000 ms"; final String durationValue = DurationHelper.createDurationValue(null, null); assertThat(durationValue).isEqualTo(expectedValue); }