Clock (java.time)

The java.time class that supplies the current time, which code can receive as a dependency so tests can control what now means.

In more detail

Production passes the system clock; a test passes Clock.fixed to choose an exact instant. Calling Instant.now(clock) instead of Instant.now() removes a hidden global and makes time-based rules deterministic.

Example

deadline.isBefore(Instant.now(clock))

Related terms

Taught in

References