package com.stanfy.helium.internal.model.tests;

import com.stanfy.helium.internal.MethodsExecutor;
import com.stanfy.helium.model.tests.BehaviourCheck;
import com.stanfy.helium.model.tests.BehaviourSuite;
import com.stanfy.helium.model.tests.CheckListener;
import org.joda.time.Duration;

import java.util.ArrayList;
import java.util.List;

import static com.stanfy.helium.model.tests.BehaviourCheck.Result.*;

public final class CheckGroup {

  private final List<? extends CheckableItem> children;
  private final MethodsExecutor executor;
  private final CheckListener listener;

  public CheckGroup(final List<? extends CheckableItem> children,
                    final MethodsExecutor executor, final CheckListener listener) {
    this.children = children;
    this.executor = executor;
    this.listener = listener;
  }

  public BehaviourSuite run(final String name) {
    BehaviourSuite res = new BehaviourSuite();
    res.setName(name);
    Duration resultDuration = Duration.ZERO;
    ArrayList<BehaviourCheck> childResults = new ArrayList<BehaviourCheck>(children.size());
    listener.onSuiteStarted(res);

    try {
      BehaviourCheck.Result resultType = children.isEmpty() ? PENDING : PASSED;
      for (CheckableItem c: children) {
        BehaviourCheck check = c.check(executor, listener);
        childResults.add(check);
        resultDuration = resultDuration.plus(check.getTime());
        switch (check.getResult()) {
          case PENDING:
            if (resultType == PASSED) {
              resultType = PENDING;
            }
            break;
          case FAILED:
            resultType = FAILED;
            break;
          default:
            // Nothing.
        }
      }
      res.setResult(resultType);
    } catch (Throwable e) {
      res.setResult(FAILED);
      res.setDescription(Util.errorStack(e));
    } finally {
      res.setChildren(childResults);
      res.setTime(resultDuration);
      listener.onSuiteDone(res);
    }

    return res;
  }

}

@@ -1796,16 +1796,118 @@
 AILED);%0A
+      if (e instanceof AssertionError) %7B%0A        res.setDescription(e.getMessage());%0A      %7D else %7B%0A  
       re
@@ -1940,24 +1940,32 @@
 rStack(e));%0A
+      %7D%0A
     %7D finall

Use less verbose error descriptions