Timer { public DiscreteInterval getTimeRemaining() { if (!wasSet) throw new IllegalStateException("cannot compute time remaining without having duration set"); if (startTime == null) return targetElapsedTime; DiscreteInterval diff = targetEndTime.minus(clock.getNanoTime()); return (diff.getMin() <= 0L) ? new DiscreteInterval(0L,0L) : diff; } Timer();  Timer(HardwareClock clock); boolean set(long duration, long error); void start(); boolean hasElapsed(); boolean isLate(); DiscreteInterval getTimeRemaining(); void waitUntilElapsed();  }
@Test(expected=IllegalStateException.class) public void cannotAskForRemainingTimeIfNotSet() { expect(mockClock.getGranularity()).andReturn(1L).anyTimes(); expect(mockClock.getNanoTime()).andReturn(new DiscreteInterval(4L,5L)).anyTimes(); replay(mockClock); impl.getTimeRemaining(); }