@Test public void testStopWhenStopped() { StopWatch stopWatch = createStopWatch(); try { stopWatch.stop(); fail("Should not be able to stop a stopped watch, (initial state is stopped)"); } catch (IllegalStateException e) { } }
public void stop() { if (state != State.RUNNING) { throw new IllegalStateException("Cannot stop a Stopwatch that is already running"); } long stopTime = timeProvider.nanoTime(); accumulatedTime += stopTime - lastStartTime; state = State.STOPPED; }
StopWatch { public void stop() { if (state != State.RUNNING) { throw new IllegalStateException("Cannot stop a Stopwatch that is already running"); } long stopTime = timeProvider.nanoTime(); accumulatedTime += stopTime - lastStartTime; state = State.STOPPED; } }
StopWatch { public void stop() { if (state != State.RUNNING) { throw new IllegalStateException("Cannot stop a Stopwatch that is already running"); } long stopTime = timeProvider.nanoTime(); accumulatedTime += stopTime - lastStartTime; state = State.STOPPED; } StopWatch(TimeProvider timeProvider); }
StopWatch { public void stop() { if (state != State.RUNNING) { throw new IllegalStateException("Cannot stop a Stopwatch that is already running"); } long stopTime = timeProvider.nanoTime(); accumulatedTime += stopTime - lastStartTime; state = State.STOPPED; } StopWatch(TimeProvider timeProvider); void start(); void stop(); long getElapsed(TimeUnit timeUnit); void combine(StopWatch that); }
StopWatch { public void stop() { if (state != State.RUNNING) { throw new IllegalStateException("Cannot stop a Stopwatch that is already running"); } long stopTime = timeProvider.nanoTime(); accumulatedTime += stopTime - lastStartTime; state = State.STOPPED; } StopWatch(TimeProvider timeProvider); void start(); void stop(); long getElapsed(TimeUnit timeUnit); void combine(StopWatch that);  }