package cucumber.runtime.junit;

import cucumber.runtime.Runtime;
import cucumber.runtime.model.CucumberExamples;
import cucumber.runtime.model.CucumberScenario;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;

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

class ExamplesRunner extends Suite {
    private final CucumberExamples cucumberExamples;
    private Description description;

    protected ExamplesRunner(Runtime runtime, CucumberExamples cucumberExamples, JUnitReporter jUnitReporter) throws InitializationError {
        super(ExamplesRunner.class, new ArrayList<Runner>());
        this.cucumberExamples = cucumberExamples;

        List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
        for (CucumberScenario scenario : exampleScenarios) {
            try {
                ExecutionUnitRunner exampleScenarioRunner = new ExecutionUnitRunner(runtime, scenario, jUnitReporter);
                getChildren().add(exampleScenarioRunner);
            } catch (InitializationError initializationError) {
                initializationError.printStackTrace();
            }
        }
    }

    @Override
    protected String getName() {
        return cucumberExamples.getExamples().getKeyword() + ": " + cucumberExamples.getExamples().getName();
    }

    @Override
    public Description getDescription() {
        if (description == null) {
            description = Description.createSuiteDescription(getName(), cucumberExamples.getExamples());
            for (Runner child : getChildren()) {
                description.addChild(describeChild(child));
            }
        }
        return description;
    }
}

@@ -224,16 +224,66 @@
 Runner;%0A
+import org.junit.runner.notification.RunNotifier;%0A
 import o
@@ -306,16 +306,16 @@
 .Suite;%0A
-
 import o
@@ -537,16 +537,57 @@
 ription;
+%0A    private JUnitReporter jUnitReporter;
 %0A%0A    pr
@@ -777,24 +777,24 @@
 Runner%3E());%0A
-
         this
@@ -830,16 +830,60 @@
 xamples;
+%0A        this.jUnitReporter = jUnitReporter;
 %0A%0A      
@@ -1901,11 +1901,175 @@
 n;%0A    %7D
+%0A%0A    @Override%0A    public void run(final RunNotifier notifier) %7B%0A        jUnitReporter.examples(cucumberExamples.getExamples());%0A        super.run(notifier);%0A    %7D
 %0A%7D%0A

call examples() see https://groups.google.com/forum/#!topic/cukes/ekQBHtnPiQQ.