public void testFailingServiceStartAndWait() throws Exception {
    StartFailingService service = new StartFailingService();
    RecordingListener listener = RecordingListener.record(service);

    try {
      service.startAndWait();
      fail();
    } catch (UncheckedExecutionException e) {
      assertEquals(EXCEPTION, e.getCause());
    }
    assertEquals(ImmutableList.of(State.STARTING, State.FAILED), listener.getStateHistory());
  }
 public void testAddListenerAfterFailureDoesntCauseDeadlock() throws InterruptedException {
   final StartFailingService service = new StartFailingService();
   service.start();
   assertEquals(State.FAILED, service.state());
   service.addListener(new RecordingListener(service), MoreExecutors.sameThreadExecutor());
   Thread thread =
       new Thread() {
         @Override
         public void run() {
           // Internally start() grabs a lock, this could be any such method on AbstractService.
           service.start();
         }
       };
   thread.start();
   thread.join(100);
   assertFalse(thread + " is deadlocked", thread.isAlive());
 }