### Question:
StopWatch extends Stated { public long lap() { if(isStarted()) { long nextTimeStamp = System.nanoTime(); long diff = nextTimeStamp - this.timeStamp; time += diff; this.timeStamp = nextTimeStamp; return time; } else { throw new IllegalStateException("not started, cannot lap"); } } StopWatch(); long getStartTime(); long lap(); long getTime(); void resetClock(); void resetTime(); void onReset(); void add(long nanos); void add(StopWatch stopWatch); @Override String toString();  }### Answer:
@Test public void testLap() throws InterruptedException { long sleepTime = TimeUnit.NANOSECONDS.convert(100, TimeUnit.MILLISECONDS); long tolerance = TimeUnit.NANOSECONDS.convert(500, TimeUnit.MILLISECONDS); stopWatch.start(); for(int i = 1; i <= 5; i++) { long sleep = TimeUnit.MILLISECONDS.convert(sleepTime, TimeUnit.NANOSECONDS); Thread.sleep(sleep); long lapTime = stopWatch.lap(); Assert.assertTrue(lapTime > sleepTime * i ); Assert.assertTrue(lapTime < (sleepTime + tolerance) * i); } }
@Test(expected = IllegalStateException.class) public void testLapWhenStopped() { stopWatch.stop(); stopWatch.lap(); }