@Test
public void testWaitForState() throws LifecycleException,
    InterruptedException {

  LifecycleAware delegate = new SleeperLifecycleDelegate();
  Assert.assertTrue(delegate.getLifecycleState().equals(LifecycleState.IDLE));
  delegate.start();
  boolean reached = LifecycleController.waitForState(delegate,
      LifecycleState.START, 2000);
  Assert.assertEquals(true, reached);
  Assert.assertEquals(LifecycleState.START, delegate.getLifecycleState());
  delegate.stop();
  reached = LifecycleController.waitForState(delegate, LifecycleState.STOP,
      2000);
  Assert.assertEquals(true, reached);
  Assert.assertEquals(LifecycleState.STOP, delegate.getLifecycleState());
  delegate.start();
  reached = LifecycleController.waitForState(delegate, LifecycleState.IDLE,
      500);
  Assert.assertEquals(false, reached);
  Assert.assertEquals(LifecycleState.START, delegate.getLifecycleState());
}