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

48 lines
1.6 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
/**
* 运营日计算(docs/flight-state.md §2.1):SODTddMMMyyHHmm+ 机场时区 + 业务切日边界。
*/
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"))
}
}