@Test
@SuppressWarnings("unchecked")
public void testExecute() {

  final String s1 = randomUUID().toString();
  final String success = randomUUID().toString();
  final String failure = randomUUID().toString();
  final Callable<Void> callable1 = new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      logger.trace("Success");
      return null;
    }
  };
  final Callable<Void> callable2 = new Callable<Void>() {
    @Override
    public Void call() throws Exception {
      throw new IllegalArgumentException();
    }
  };
  final StateChangeListener<String> listener = mock(StateChangeListener.class);
  final StateMachine<String> stateMachine = new StateMachine<String>(s1);
  stateMachine.addListener(listener);
  stateMachine.execute(callable1, success, failure);
  assertEquals(success, stateMachine.getState());
  stateMachine.execute(callable2, success, failure);
  assertEquals(failure, stateMachine.getState());
  stateMachine.removeListener(listener);
}