DefaultHardwareClock implements HardwareClock { long elapsedTime(long start, long end) { if (end > start) return (end - start); return (Long.MAX_VALUE - start) + 1 + (end - Long.MIN_VALUE); } DefaultHardwareClock();  DefaultHardwareClock(Env env);  DefaultHardwareClock(Env env, int numSamples, long periodMillis); long getGranularity(); DiscreteInterval getNanoTime();  }
@Test public void elapsedTimeWorksIfNoElapsedTime() { assertEquals(0L, impl.elapsedTime(1L, 1L)); }
@Test public void elapsedTimeWorksWhenNoOverflow() { assertEquals(3L, impl.elapsedTime(4L,7L)); }
@Test public void elapsedTimeWorksWhenOverflowed() { long start = Long.MAX_VALUE - 3L; long end = start + 10L; assertEquals(10L, impl.elapsedTime(start, end)); }