📜  kotlin 模拟时间 - Kotlin 代码示例

📅  最后修改于: 2022-03-11 14:53:33.478000             🧑  作者: Mango

代码示例1
private val now = 1550160535168L
    private val fixedClock = Clock.fixed(Instant.ofEpochMilli(now), ZoneId.systemDefault())

    @BeforeEach
    fun `fix the clock =)`() {
        mockkStatic(Clock::class)
        // Default system clock
        every { Clock.systemUTC() } returns fixedClock
    }

    @Test
    fun `can fix clock`() {
        assertEquals(now, Instant.now().toEpochMilli())
    }