<commit_before>package ballad;

import static org.junit.runner.Description.createSuiteDescription;
import static org.junit.runner.Description.createTestDescription;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
import org.junit.runners.model.InitializationError;

public class Balladeer extends ParentRunner<Postcondition> {
  private final List<Postcondition> accumulator;
  private final Class<?> spec;
  private final Description description;
  private final Map<Object, Description> cache;

  public Balladeer(Class<?> spec) throws InitializationError {
    this(new ArrayList<Postcondition>(), new Context(spec), spec);
  }

  private Balladeer(List<Postcondition> acc, Context context, Class<?> spec) throws InitializationError {
    this(new RecordingScribe(acc, context), acc, context, spec);
  }

  Balladeer(Scribe s, List<Postcondition> acc, Context root, Class<?> spec) throws InitializationError {
    super(spec);
    this.accumulator = acc;
    this.spec = spec;
    this.description = createSuiteDescription(spec);
    this.cache = new HashMap<>();

    cache.put(root, description);
    Ballad.recruit(s);
    try {
      spec.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
      throw new InitializationError(e);
    }
    Ballad.retire(s);

    // prime all the descriptions
    acc.stream().forEachOrdered(p -> { this.asJUnitDescription(p); });
  }

  @Override
  protected List<Postcondition> getChildren() {
    return accumulator;
  }

  @Override
  public Description getDescription() {
    return description;
  }

  @Override
  protected Description describeChild(Postcondition postcondition) {
    return cache.get(postcondition);
  }

  private Description asJUnitDescription(Postcondition postcondition) {
    Description result = cache.get(postcondition);
    if (result == null) {
      Deque<Context> stack = contexts(postcondition.context());
      stack.stream()
      .filter(c -> !cache.containsKey(c))
      .forEachOrdered(c -> {
        Description desc = createSuiteDescription(c.description());
        cache.get(c.context()).addChild(desc);
        cache.put(c, desc);
      });

      String stanza = stack.stream()
          .map(Context::description)
          .collect(Collectors.joining(" "));
      result = createTestDescription(spec, String.format("%s (%h)", stanza, postcondition.hashCode()));
      cache.get(postcondition.context()).addChild(result);
      cache.put(postcondition, result);
    }
    return result;
  }

  private Deque<Context> contexts(Context context) {
    Deque<Context> stack = new ArrayDeque<>();
    while (!context.isRoot()) {
      stack.push(context);
      context = context.context();
    }
    return stack;
  }

  @Override
  protected void runChild(Postcondition postcondition, RunNotifier notifier) {
    notifier.fireTestStarted(cache.get(postcondition));
    try {
      Deque<Context> stack = contexts(postcondition.context());
      stack.stream()
      .map(ctx -> ctx.preconditions())
      .flatMap(l -> l.stream())
      .forEachOrdered(Precondition::establish);
      postcondition.verify();
    } catch (AssertionError|SpecificationError e) {
      notifier.fireTestFailure(new Failure(cache.get(postcondition), e));
    }
  }
}<commit_msg>remove unecessary notification of tests starting<commit_after>package ballad;

import static org.junit.runner.Description.createSuiteDescription;
import static org.junit.runner.Description.createTestDescription;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.ParentRunner;
import org.junit.runners.model.InitializationError;

public class Balladeer extends ParentRunner<Postcondition> {
  private final List<Postcondition> accumulator;
  private final Class<?> spec;
  private final Description description;
  private final Map<Object, Description> cache;

  public Balladeer(Class<?> spec) throws InitializationError {
    this(new ArrayList<Postcondition>(), new Context(spec), spec);
  }

  private Balladeer(List<Postcondition> acc, Context context, Class<?> spec) throws InitializationError {
    this(new RecordingScribe(acc, context), acc, context, spec);
  }

  Balladeer(Scribe s, List<Postcondition> acc, Context root, Class<?> spec) throws InitializationError {
    super(spec);
    this.accumulator = acc;
    this.spec = spec;
    this.description = createSuiteDescription(spec);
    this.cache = new HashMap<>();

    cache.put(root, description);
    Ballad.recruit(s);
    try {
      spec.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
      throw new InitializationError(e);
    }
    Ballad.retire(s);

    // prime all the descriptions
    acc.stream().forEachOrdered(p -> { this.asJUnitDescription(p); });
  }

  @Override
  protected List<Postcondition> getChildren() {
    return accumulator;
  }

  @Override
  public Description getDescription() {
    return description;
  }

  @Override
  protected Description describeChild(Postcondition postcondition) {
    return cache.get(postcondition);
  }

  private Description asJUnitDescription(Postcondition postcondition) {
    Description result = cache.get(postcondition);
    if (result == null) {
      Deque<Context> stack = contexts(postcondition.context());
      stack.stream()
      .filter(c -> !cache.containsKey(c))
      .forEachOrdered(c -> {
        Description desc = createSuiteDescription(c.description());
        cache.get(c.context()).addChild(desc);
        cache.put(c, desc);
      });

      String stanza = stack.stream()
          .map(Context::description)
          .collect(Collectors.joining(" "));
      result = createTestDescription(spec, String.format("%s (%h)", stanza, postcondition.hashCode()));
      cache.get(postcondition.context()).addChild(result);
      cache.put(postcondition, result);
    }
    return result;
  }

  private Deque<Context> contexts(Context context) {
    Deque<Context> stack = new ArrayDeque<>();
    while (!context.isRoot()) {
      stack.push(context);
      context = context.context();
    }
    return stack;
  }

  @Override
  protected void runChild(Postcondition postcondition, RunNotifier notifier) {
    try {
      Deque<Context> stack = contexts(postcondition.context());
      stack.stream()
      .map(ctx -> ctx.preconditions())
      .flatMap(l -> l.stream())
      .forEachOrdered(Precondition::establish);
      postcondition.verify();
    } catch (AssertionError|SpecificationError e) {
      notifier.fireTestFailure(new Failure(cache.get(postcondition), e));
    }
  }
}
{'fraction_non_alphanumeric': 0.11987690586095957, 'fraction_numerical': 0.0, 'mean_word_length': 3.9825783972125435, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2253130', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1995, 'n_words': 436}