Timer { public boolean set(long duration, long error) { if (error < clock.getGranularity()) return false; wasSet = true; targetElapsedTime = new DiscreteInterval(duration - error, duration + error); return true; } Timer();  Timer(HardwareClock clock); boolean set(long duration, long error); void start(); boolean hasElapsed(); boolean isLate(); DiscreteInterval getTimeRemaining(); void waitUntilElapsed();  }
@Test public void canSetTimer() { impl.set(40000L,3000L); }
@Test public void cannotSetATimerWithASmallerErrorThanClockGranularity() { expect(mockClock.getGranularity()).andReturn(1000L).anyTimes(); replay(mockClock); assertFalse(impl.set(1000L, 500L)); verify(mockClock); }