1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| package org.dromara.hutool.core.date.chinese;
import org.dromara.hutool.core.date.DateUnit; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows;
public class ShiChenTest {
@Test void testToModernTime() { assertEquals(2, ShiChen.toModernTime("子时").between(DateUnit.HOUR));
assertEquals(1, ShiChen.toModernTime("子初").between(DateUnit.HOUR)); assertEquals(1, ShiChen.toModernTime("子正").between(DateUnit.HOUR));
String[] times = {"子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"}; for (String time : times) { assertEquals(2, ShiChen.toModernTime(time + "时").between(DateUnit.HOUR)); assertEquals(1, ShiChen.toModernTime(time + "初").between(DateUnit.HOUR)); assertEquals(1, ShiChen.toModernTime(time + "正").between(DateUnit.HOUR)); } assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime("无效时")); assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime("无效正")); assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime("")); assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime(null)); }
@Test void testToShiChen() { assertEquals("子时", ShiChen.toShiChen(23, true)); assertEquals("子时", ShiChen.toShiChen(0, true));
assertEquals("子正", ShiChen.toShiChen(0, false)); assertEquals("丑初", ShiChen.toShiChen(1, false));
assertEquals("未知", ShiChen.toShiChen(24, true)); assertEquals("未知", ShiChen.toShiChen(-1, false)); }
}
|