<commit_before>package j8spec.junit;

import j8spec.ExecutionPlan;
import j8spec.ItBlock;
import j8spec.J8Spec;
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;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static java.util.Collections.unmodifiableList;
import static org.junit.runner.Description.createTestDescription;

public final class J8SpecRunner extends ParentRunner<ItBlock> {

    private final ExecutionPlan executionPlan;
    private final Map<ItBlock, Description> descriptions = new HashMap<>();
    private List<ItBlock> itBlocks;

    public J8SpecRunner(Class<?> testClass) throws InitializationError {
        super(testClass);
        try {
            executionPlan = J8Spec.executionPlanFor(testClass);
        } catch (Exception e) {
            throw new InitializationError(e);
        }
    }

    @Override
    protected List<ItBlock> getChildren() {
        if (itBlocks == null) {
            itBlocks = unmodifiableList(executionPlan.allItBlocks());
        }
        return itBlocks;
    }

    @Override
    protected Description describeChild(ItBlock itBlock) {
        if (!descriptions.containsKey(itBlock)) {
            descriptions.put(
                itBlock,
                createTestDescription(executionPlan.specClass().getName(), buildChildName(itBlock))
            );
        }
        return descriptions.get(itBlock);
    }

    private String buildChildName(ItBlock itBlock) {
        List<String> name = new LinkedList<>();
        List<String> containerDescriptions = itBlock.containerDescriptions();
        name.add(itBlock.getDescription());
        for (int i = 1; i < containerDescriptions.size(); i++) {
            name.add(containerDescriptions.get(i));
        }
        return String.join(", ", name);
    }

    @Override
    protected void runChild(ItBlock itBlock, RunNotifier notifier) {
        notifier.fireTestStarted(describeChild(itBlock));
        try {
            for (Runnable beforeEachBlock : itBlock.beforeEachBlocks()) {
                beforeEachBlock.run();
            }
            itBlock.getBody().run();
        } catch (Throwable t) {
            notifier.fireTestFailure(new Failure(describeChild(itBlock), t));
        }
        notifier.fireTestFinished(describeChild(itBlock));
    }
}<commit_msg>Replaces 'for' loop by 'forEach' call.<commit_after>package j8spec.junit;

import j8spec.ExecutionPlan;
import j8spec.ItBlock;
import j8spec.J8Spec;
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;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static java.util.Collections.unmodifiableList;
import static org.junit.runner.Description.createTestDescription;

public final class J8SpecRunner extends ParentRunner<ItBlock> {

    private final ExecutionPlan executionPlan;
    private final Map<ItBlock, Description> descriptions = new HashMap<>();
    private List<ItBlock> itBlocks;

    public J8SpecRunner(Class<?> testClass) throws InitializationError {
        super(testClass);
        try {
            executionPlan = J8Spec.executionPlanFor(testClass);
        } catch (Exception e) {
            throw new InitializationError(e);
        }
    }

    @Override
    protected List<ItBlock> getChildren() {
        if (itBlocks == null) {
            itBlocks = unmodifiableList(executionPlan.allItBlocks());
        }
        return itBlocks;
    }

    @Override
    protected Description describeChild(ItBlock itBlock) {
        if (!descriptions.containsKey(itBlock)) {
            descriptions.put(
                itBlock,
                createTestDescription(executionPlan.specClass().getName(), buildChildName(itBlock))
            );
        }
        return descriptions.get(itBlock);
    }

    private String buildChildName(ItBlock itBlock) {
        List<String> name = new LinkedList<>();
        List<String> containerDescriptions = itBlock.containerDescriptions();
        name.add(itBlock.getDescription());
        for (int i = 1; i < containerDescriptions.size(); i++) {
            name.add(containerDescriptions.get(i));
        }
        return String.join(", ", name);
    }

    @Override
    protected void runChild(ItBlock itBlock, RunNotifier notifier) {
        notifier.fireTestStarted(describeChild(itBlock));
        try {
            itBlock.beforeEachBlocks().forEach(Runnable::run);
            itBlock.getBody().run();
        } catch (Throwable t) {
            notifier.fireTestFailure(new Failure(describeChild(itBlock), t));
        }
        notifier.fireTestFinished(describeChild(itBlock));
    }
}
{'fraction_non_alphanumeric': 0.10261529247354761, 'fraction_numerical': 0.0035935316430425234, 'mean_word_length': 2.988853503184713, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, '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': '924238', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1350, 'n_words': 273}