Utils { public static String formatDuration(Duration duration) { long days = duration.toDays(); long hours = duration.toHours(); long minutes = duration.toMinutes(); long seconds = duration.getSeconds(); long milliseconds = duration.toMillis(); return (days > 0 ? days + "d " : "") + (hours > 0 ? (hours - TimeUnit.DAYS.toHours(days)) + "hr " : "") + (minutes > 0 ? (minutes - TimeUnit.HOURS.toMinutes(hours)) + "min " : "") + (seconds > 0 ? (seconds - TimeUnit.MINUTES.toSeconds(minutes)) + "sec " : "") + (milliseconds -TimeUnit.SECONDS.toMillis(seconds)) + "ms"; } private  Utils(); static void checkNotNull(Object argument, String argumentName); static void checkArgument(boolean assertion, String message); static Map<String, Method> getGetters(final Class<?> type); static String formatTime(LocalDateTime time); static String formatDuration(Duration duration); static String formatErrorThreshold(final long errorThreshold); static List<P> extractPayloads(final List<? extends Record<P>> records); static Class<?> getGenericTypeNameFromTypeConverter(TypeConverter<?, ?> typeConverter, int genericTypeIndex); static final String LINE_SEPARATOR; static final String FILE_SEPARATOR; static final String JAVA_IO_TMPDIR; static final String NOT_APPLICABLE; }
@Test public void testFormatDuration() { assertThat(Utils.formatDuration(Duration.of(100, ChronoUnit.MILLIS))).isEqualTo("100ms"); assertThat(Utils.formatDuration(Duration.of(1, ChronoUnit.SECONDS))).isEqualTo("1sec 0ms"); assertThat(Utils.formatDuration(Duration.of(2, ChronoUnit.MINUTES))).isEqualTo("2min 0sec 0ms"); assertThat(Utils.formatDuration(Duration.of(2, ChronoUnit.HOURS))).isEqualTo("2hr 0min 0sec 0ms"); assertThat(Utils.formatDuration(Duration.of(2, ChronoUnit.DAYS))).isEqualTo("2d 0hr 0min 0sec 0ms"); assertThat(Utils.formatDuration(Duration.of(366, ChronoUnit.DAYS))).isEqualTo("366d 0hr 0min 0sec 0ms"); }