PeriodicJobServiceImpl extends StateGuardLifecycleSupport implements PeriodicJobService { public synchronized void stopUsing() throws Exception { checkState(activeClients > 0, "Not started"); activeClients--; if (activeClients == 0) { stop(); } }  synchronized void startUsing(); synchronized void stopUsing(); @Override @Guarded(by = STARTED) PeriodicJob schedule(final Runnable runnable, final int repeatPeriodSeconds);  }
@Test(expected = IllegalStateException.class) public void testStopUsing_InvalidPrecondition() throws Exception { service.stopUsing(); }