private Machine createMachine(MachineConfiguration machineConfiguration) {
   Collection<Context> contexts = createContexts(machineConfiguration);
   Machine machine = new SimpleMachine(contexts);
   for (Context context : machine.getContexts()) {
     if (context instanceof Observer) {
       machine.addObserver((Observer) context);
     }
   }
   return machine;
 }
 private void updateResult(Result result, Machine machine) {
   int completed = 0, failed = 0, notExecuted = 0, incomplete = 0;
   for (Context context : machine.getContexts()) {
     switch (context.getExecutionStatus()) {
       case COMPLETED:
         {
           completed++;
         }
         break;
       case FAILED:
         {
           failed++;
         }
         break;
       case NOT_EXECUTED:
         {
           notExecuted++;
         }
         break;
       case EXECUTING:
         {
           incomplete++;
         }
     }
   }
   result.setCompletedCount(completed);
   result.setFailedCount(failed);
   result.setNotExecutedCount(notExecuted);
   result.setIncompleteCount(incomplete);
   for (MachineException exception : getFailures()) {
     result.addError(getStackTrace(exception.getCause()));
   }
 }
 @Override
 public Result execute(boolean ignoreErrors) {
   result = new Result(machine.getContexts().size());
   executeAnnotation(BeforeExecution.class, machine);
   try {
     Context context = null;
     while (machine.hasNextStep()) {
       if (null != context) {
         executeAnnotation(BeforeElement.class, context);
       }
       context = machine.getNextStep();
       executeAnnotation(AfterElement.class, context);
     }
   } catch (MachineException e) {
     failures.put(e.getContext(), e);
   }
   executeAnnotation(AfterExecution.class, machine);
   updateResult(result, machine);
   if (!ignoreErrors && !failures.isEmpty()) {
     throw new TestExecutionException("Test execution contains failures");
   }
   return result;
 }
 private void executeAnnotation(Class<? extends Annotation> annotation, Machine machine) {
   for (Context context : machine.getContexts()) {
     executeAnnotation(annotation, context);
   }
 }