ClockUtil { public static long elapsedTime(long beginTime) { return currentTimeMillis() - beginTime; }  static long elapsedTime(long beginTime); static synchronized DummyClock useDummyClock(); static synchronized DummyClock useDummyClock(long timeStampMills); static synchronized DummyClock useDummyClock(Date date); static synchronized void useDefaultClock(); static Date currentDate(); static long currentTimeMillis(); static long nanoTime();  }
@Test public void elapsedTime() { try { DummyClock clock = ClockUtil.useDummyClock(2000); clock.increaseTime(1000); assertThat(ClockUtil.elapsedTime(2000)).isEqualTo(1000); } finally { ClockUtil.useDefaultClock(); } }