Timeformat Test formatting

This commit is contained in:
Tim Holloway 2022-01-10 16:55:52 -05:00
parent 596093e979
commit ce7576e459
2 changed files with 15 additions and 2 deletions

View File

@ -48,7 +48,11 @@ public class TimeFormatter {
if (mm > 0) { if (mm > 0) {
sb.append(mm); sb.append(mm);
if ((ss == 0) && (hh == 0)) { if ((ss == 0) && (hh == 0)) {
sb.append(" minutes"); if ( mm == 1 ) {
sb.append(" minute");
} else {
sb.append(" minutes");
}
} else { } else {
sb.append("min. "); sb.append("min. ");
} }

View File

@ -25,7 +25,7 @@ class TimeFormatterTest {
} }
@Test @Test
void test() { void testParse() {
assertEquals(5000, assertEquals(5000,
TimeFormatter.parseTime("5s").longValue()); TimeFormatter.parseTime("5s").longValue());
assertEquals(5000 * 60, assertEquals(5000 * 60,
@ -48,4 +48,13 @@ class TimeFormatterTest {
assertNull(TimeFormatter.parseTime("1 week")); assertNull(TimeFormatter.parseTime("1 week"));
} }
@Test
void testFormat() {
assertEquals("1 minute",
TimeFormatter.formatTime(60_000L));
assertEquals("1h 30min.",
TimeFormatter.formatTime(90*60_000L));
assertEquals("1d 1h 20min.",
TimeFormatter.formatTime(24*3600_000L + 3600_000L + 20*60_000L));
}
} }