Compatibility with java.time • opensavvy.prepared.compat.java.time • set
set¶
@ExperimentalCoroutinesApi
suspend fun Time.set(instant: Instant)
Advances the virtual time until it reaches instant
.
This function is identical in behavior to delayUntil
. It exists because tests often read better when using it to set the initial date:
test("Some test") {
// Given:
time.set(Instant.parse("2024-02-13T21:32:41Z"))
// When:
// …
delayUntil(Instant.parse("2024-02-13T21:35:01Z"))
// …
// Then:
// …
}
We recommend using set
to set the initial date at the very start of a test, and using delayUntil
inside the test logic.
It is not possible to set the time to a date in the past.