package cucumber.runtime.junit;

import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.platform.engine.TestDescriptor;

import static cucumber.runtime.junit.CucumberFeatureMother.anyFeatureFile;
import static cucumber.runtime.junit.UniqueIdMatcher.endsWith;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.platform.engine.UniqueId.forEngine;

public class CucumberEngine_IdAssignmentTest implements CucumberEngineTestSugar {

    private final CucumberEngineFixture fixture = new CucumberEngineFixture();
    private final CucumberFeatureBuilder cucumberFeatureBuilder = anyFeatureFile();

    @After
    public void allTestDescriptorsAreInAProperState() throws Exception {
        fixture.engineExecutionListener.ensureAllInProperEndState();
    }

    @Test
    public void topLevelCucumberEngine() throws Exception {
        assertThat(engineDescriptor().getUniqueId(), equalTo(forEngine("cucumber-jvm")));
    }

    @Test
    public void pathToFeatureFile() throws Exception {
        cucumberFeatureBuilder.path("/the/path");

        assertThat(featureDescriptor().getUniqueId(), endsWith("feature", "/the/path"));
    }

    @Test
    public void scenarioId() throws Exception {
        cucumberFeatureBuilder.Scenario("first line of the scenario\nextended description");

        assertThat(scenarioDescriptor().getUniqueId(), endsWith("scenario", "feature-name;first-line-of-the-scenario"));
    }

    @Test
    @Ignore
    public void name() throws Exception {
        CucumberEngineDescriptor engineDescriptor = discoveredDescriptorsFor(
                anyFeatureFile().ScenarioOutline("text take\nExtended discription")
                        .Given("<arg1> <arg2>")
                        .Example("one", "two")
                        .Example("A", "B"));

        System.out.println(engineDescriptor);
    }

    private TestDescriptor scenarioDescriptor() {
        return featureDescriptor().getChildren().iterator().next();
    }

    private TestDescriptor featureDescriptor() {
        return engineDescriptor().getChildren().iterator().next();
    }

    private CucumberEngineDescriptor engineDescriptor() {
        return discoveredDescriptorsFor(cucumberFeatureBuilder);
    }

    @Override
    public CucumberEngineFixture fixture() {
        return fixture;
    }
}
@@ -1507,32 +1507,357 @@
 ario%22));%0A    %7D%0A%0A
+    @Test%0A    public void scenarioOutlineId() throws Exception %7B%0A        cucumberFeatureBuilder.ScenarioOutline(%22first line of the scenario outline%5Cnextended description%22);%0A%0A        assertThat(scenarioOutlineDescriptor().getUniqueId(), endsWith(%22scenario-outline%22, %22feature-name;first-line-of-the-scenario-outline%22));%0A    %7D%0A%0A
     @Test%0A    @I
@@ -2252,32 +2252,164 @@
 riptor);%0A    %7D%0A%0A
+    private TestDescriptor scenarioOutlineDescriptor() %7B%0A        return featureDescriptor().getChildren().iterator().next();%0A    %7D%0A%0A
     private Test

test for ScenarioOutlineDescriptor unique id