public class ConstantNowTestListener<Time extends Temporal>
extends ConstantNowListener
Simulate the value of now() while executing a test
This listener will simulate the value returned by the static method now as a helper to code that is sensitive
to now. After the execution of the test, the default behavior will be returned.
Supported classes are all classes in the java.time package that supports now, such as LocalDate.now() and
LocalDateTime.now(). Less used classes such as JapaneseDate.now() or Year.now() are also supported.
To simulate the value, this listener uses Mockk to modify the value returned from the static now function
ATTENTION: This code is very sensitive to race conditions. as the static method is global to the whole JVM instance,
if you're mocking now while running in parallel, the results may be inconsistent.
| Constructor and Description |
|---|
ConstantNowTestListener(Time now)
Simulate the value of now() while executing a test
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterTest(io.kotlintest.TestCase testCase,
io.kotlintest.TestResult result) |
void |
beforeTest(io.kotlintest.TestCase testCase) |
changeNow, resetNowpublic ConstantNowTestListener(Time now)
Simulate the value of now() while executing a test
This listener will simulate the value returned by the static method now as a helper to code that is sensitive
to now. After the execution of the test, the default behavior will be returned.
Supported classes are all classes in the java.time package that supports now, such as LocalDate.now() and
LocalDateTime.now(). Less used classes such as JapaneseDate.now() or Year.now() are also supported.
To simulate the value, this listener uses Mockk to modify the value returned from the static now function
ATTENTION: This code is very sensitive to race conditions. as the static method is global to the whole JVM instance,
if you're mocking now while running in parallel, the results may be inconsistent.