You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.4 KiB
60 lines
1.4 KiB
/**
|
|
* Copyright (C) 2022, Tim Holloway
|
|
*
|
|
* Date written: Jan 8, 2022
|
|
* Author: Tim Holloway <timh@mousetech.com>
|
|
*/
|
|
package com.mousetech.gourmetj.utils;
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
/**
|
|
* @author timh
|
|
* @since Jan 8, 2022
|
|
*/
|
|
class TimeFormatterTest {
|
|
|
|
/**
|
|
* @throws java.lang.Exception
|
|
*/
|
|
@BeforeAll
|
|
static void setUpBeforeClass() throws Exception {
|
|
}
|
|
|
|
@Test
|
|
void testParse() {
|
|
assertEquals(5000,
|
|
TimeFormatter.parseTime("5s").longValue());
|
|
assertEquals(5000 * 60,
|
|
TimeFormatter.parseTime("5m").longValue());
|
|
|
|
assertEquals(3600_000L + 25 * 60_000, TimeFormatter
|
|
.parseTime("1 hour, 25 min").longValue());
|
|
|
|
assertEquals(5 * 3600000 + 6 * 60000,
|
|
TimeFormatter.parseTime("5h 6m").longValue());
|
|
assertEquals(277562000L,
|
|
TimeFormatter.parseTime("3d 5h 6m 2s").longValue());
|
|
|
|
assertEquals(18000000L,
|
|
TimeFormatter.parseTime("1.5 hours").longValue());
|
|
|
|
assertEquals(3 * 3600_000,
|
|
TimeFormatter.parseTime("3 hours").longValue());
|
|
|
|
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));
|
|
}
|
|
}
|
|
|