Skip to main content

Practice ยท 1 of 3

Freeze Time Behind a Seam

Design time-dependent logic testably inside Solution: - interface Clock { java.time.Instant now(); } - static class Trial with a constructor (Clock clock); method boolean isActive(java.time.Instant start, java.time.Instant end) returning !clock.now().isBefore(start) && clock.now().isBefore(end). - static Clock frozenAt(String iso) โ€” a Clock pinned to that instant. The tests freeze time instead of sleeping โ€” the entire point of the seam.

Difficulty: intermediate

Back to lesson: Practice: Testing Lab