Timer { public synchronized void stop() { if (!stopwatch.isRunning()) { throw new IllegalStateException("Already stopped"); } stopwatch.stop(); this.elapsedTime = stopwatch.elapsed(TimeUnit.MICROSECONDS); eventBus.post(new TimerEvent(this, target, elapsedTime)); } @Inject  Timer(EventBus eventBus, @Assisted Object target); @VisibleForTesting  Timer(EventBus eventBus, Object target, Stopwatch stopwatch); synchronized void started(); synchronized void stop(); synchronized void reset(); void time(Runnable target); long getElapsedTime();  }
@Test(expected = IllegalStateException.class) public void testStoppedWhenNotStarted() { Timer timer = new Timer(eventBus, this); timer.stop(); fail("Timer should have thrown an exception"); }