DateTimeUtil { public static String asHoursMinutesSeconds(long milliseconds) { if (milliseconds < 0) { throw new IllegalArgumentException(); } long seconds = 0; long minutes = 0; long hours = 0; if (milliseconds > 1000) { seconds = milliseconds / 1000; } if (seconds > 60) { minutes = seconds / 60; seconds = seconds % 60; } if (minutes > 60) { hours = minutes / 60; minutes = minutes % 60; } StringBuilder res = new StringBuilder(); if (hours > 0) { res.append(hours).append("h "); } if (hours > 0 || minutes > 0) { res.append(minutes).append("m "); } res.append(seconds).append('s'); return res.toString(); } private  DateTimeUtil(); static String asHoursMinutesSeconds(long milliseconds);  }
@Test public void testConversions() { Collection<Object[]> stringNumberPairs = ReadableDurationTest.data(); for (Object[] stringAndNumber : stringNumberPairs) { String result = (String) stringAndNumber[0]; Integer milliseconds = (Integer) stringAndNumber[1]; assertEquals(result, DateTimeUtil.asHoursMinutesSeconds(milliseconds)); } }