3 ms·
Have a look at this method on Java's Instant class for an example. https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html#now-java.time.Clock- https:
by EdwardDiego 3y ago
Have a look at this method on Java's Instant class for an example.
https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html#now-java.time.Clock- https://docs.oracle.com/javase/8/docs/api/java/time/Instant....
Code under test creates Instant, so long as it uses the Clock you've passed in, you'll control how it determines when now() is.
You've got several built-in testing clocks like this one[1], but can also implement your own.
[1]: https://docs.oracle.com/javase/8/docs/api/java/time/Clock.html#fixed-java.time.Instant-java.time.ZoneId- https://docs.oracle.com/javase/8/docs/api/java/time/Clock.ht...