Files
msgexchange-v2/src/test/kotlin/com/gzzn/omms/msgexchange/domain/OperationDayTest.kt
T

49 lines
1.8 KiB
Kotlin
Raw Normal View History

package com.gzzn.omms.msgexchange.domain
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test
import java.time.LocalDate
import java.time.ZoneId
/**
* 守着运营日的算法:用计划运行时间 SODT(ddMMMyyHHmm)加机场时区算,本地时刻早于切日边界的
* 归到前一个运营日;越界的切日边界收敛到 23;SODT 缺失或格式不对就返回 null。
*/
class OperationDayTest {
private val zone: ZoneId = ZoneId.of("Asia/Shanghai")
@Test
fun `computes operation day from SODT with zero cutoff`() {
val calc = OperationDayCalculator(zone, cutoffHour = 0)
assertEquals(LocalDate.of(2026, 12, 15), calc.compute("15DEC261723"))
}
@Test
fun `time before cutoff rolls back to previous operation day`() {
val calc = OperationDayCalculator(zone, cutoffHour = 4)
// 04:00 之前 → 前一运营日
assertEquals(LocalDate.of(2026, 12, 14), calc.compute("15DEC260230"))
// 04:00 整点起归属当日
assertEquals(LocalDate.of(2026, 12, 15), calc.compute("15DEC260400"))
}
@Test
fun `invalid or missing SODT returns null`() {
val calc = OperationDayCalculator(zone, 0)
assertNull(calc.compute(null))
assertNull(calc.compute(""))
assertNull(calc.compute("garbage"))
assertNull(calc.compute("99XXC12345"))
}
@Test
fun `cutoff outside 0 to 23 is clamped to 23`() {
val calc = OperationDayCalculator(zone, cutoffHour = 99)
// 越界收敛为 23:当日 00:00 早于 23 点 → 归属前一运营日
assertEquals(LocalDate.of(2026, 12, 14), calc.compute("15DEC260000"))
}
}