[improve] code format

This commit is contained in:
VampireAchao 2024-02-27 01:20:50 +08:00 committed by VampireAchao
parent 0e4fa57574
commit 2f2076b1ea

View File

@ -1,9 +1,11 @@
package org.dromara.hutool.core.date.chinese; package org.dromara.hutool.core.date.chinese;
import org.dromara.hutool.core.date.DateUnit; import org.dromara.hutool.core.date.DateUnit;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* ShiChenTest * ShiChenTest
* *
@ -14,46 +16,38 @@ public class ShiChenTest {
@Test @Test
void testToModernTime() { void testToModernTime() {
// 测试后缀的转换表示整个时辰 // 测试后缀的转换表示整个时辰
Assertions.assertEquals(2, ShiChen.toModernTime("子时").between(DateUnit.HOUR)); assertEquals(2, ShiChen.toModernTime("子时").between(DateUnit.HOUR));
// 测试后缀的转换表示时辰的前半段和后半段 // 测试后缀的转换表示时辰的前半段和后半段
Assertions.assertEquals(1, ShiChen.toModernTime("子初").between(DateUnit.HOUR)); assertEquals(1, ShiChen.toModernTime("子初").between(DateUnit.HOUR));
Assertions.assertEquals(1, ShiChen.toModernTime("子正").between(DateUnit.HOUR)); assertEquals(1, ShiChen.toModernTime("子正").between(DateUnit.HOUR));
// 测试所有时辰 // 测试所有时辰
String[] times = {"", "", "", "", "", "", "", "", "", "", "", ""}; String[] times = {"", "", "", "", "", "", "", "", "", "", "", ""};
for (String time : times) { for (String time : times) {
Assertions.assertEquals(2, ShiChen.toModernTime(time + "").between(DateUnit.HOUR)); assertEquals(2, ShiChen.toModernTime(time + "").between(DateUnit.HOUR));
Assertions.assertEquals(1, ShiChen.toModernTime(time + "").between(DateUnit.HOUR)); assertEquals(1, ShiChen.toModernTime(time + "").between(DateUnit.HOUR));
Assertions.assertEquals(1, ShiChen.toModernTime(time + "").between(DateUnit.HOUR)); assertEquals(1, ShiChen.toModernTime(time + "").between(DateUnit.HOUR));
} }
Assertions.assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime("无效时"));
ShiChen.toModernTime("无效时"); assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime("无效正"));
}); assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime(""));
Assertions.assertThrows(IllegalArgumentException.class, () -> { assertThrows(IllegalArgumentException.class, () -> ShiChen.toModernTime(null));
ShiChen.toModernTime("无效正");
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ShiChen.toModernTime("");
});
Assertions.assertThrows(IllegalArgumentException.class, () -> {
ShiChen.toModernTime(null);
});
} }
@Test @Test
void testToShiChen() { void testToShiChen() {
// 测试小时转换为长安时辰不包含 // 测试小时转换为长安时辰不包含
Assertions.assertEquals("子时", ShiChen.toShiChen(23, true)); assertEquals("子时", ShiChen.toShiChen(23, true));
Assertions.assertEquals("子时", ShiChen.toShiChen(0, true)); assertEquals("子时", ShiChen.toShiChen(0, true));
// 测试小时转换为长安时辰包含 // 测试小时转换为长安时辰包含
Assertions.assertEquals("子正", ShiChen.toShiChen(0, false)); assertEquals("子正", ShiChen.toShiChen(0, false));
Assertions.assertEquals("丑初", ShiChen.toShiChen(1, false)); assertEquals("丑初", ShiChen.toShiChen(1, false));
// 测试边界条件 // 测试边界条件
Assertions.assertEquals("未知", ShiChen.toShiChen(24, true)); assertEquals("未知", ShiChen.toShiChen(24, true));
Assertions.assertEquals("未知", ShiChen.toShiChen(-1, false)); assertEquals("未知", ShiChen.toShiChen(-1, false));
} }
} }