package io.cucumber.gherkin;

import io.cucumber.messages.Messages.Envelope;
import io.cucumber.messages.Messages.GherkinDocument;
import io.cucumber.messages.Messages.Pickle;
import org.junit.Test;

import java.util.List;
import java.util.stream.Collectors;

import static io.cucumber.gherkin.Gherkin.makeSourceEnvelope;
import static java.util.Collections.singletonList;
import static org.junit.Assert.assertEquals;

public class GherkinTest {
    @Test
    public void provides_access_to_the_ast() {
        List<Envelope> envelopes = Gherkin.fromPaths(singletonList("testdata/good/minimal.feature"), false, true, false).collect(Collectors.toList());

        // Get the AST
        GherkinDocument gherkinDocument = envelopes.get(0).getGherkinDocument();

        // Get the Feature node of the AST
        GherkinDocument.Feature feature = gherkinDocument.getFeature();
        assertEquals("Minimal", feature.getName());

        // Get the first Scenario node of the Feature node
        GherkinDocument.Feature.Scenario scenario = feature.getChildren(0).getScenario();
        assertEquals("minimalistic", scenario.getName());
    }

    @Test
    public void provides_access_to_pickles_which_are_compiled_from_the_ast() {
        List<Envelope> envelopes = Gherkin.fromPaths(singletonList("testdata/good/scenario_outline.feature"), false, false, true).collect(Collectors.toList());

        // Get the first pickle
        Pickle pickle = envelopes.get(0).getPickle();

        // Get the first step of the pickle
        Pickle.PickleStep step = pickle.getSteps(0);
        assertEquals("the minimalism", step.getText());
    }

    @Test
    public void parses_supplied_source() {
        Envelope envelope = makeSourceEnvelope("Feature: Minimal\n" +
                "\n" +
                "  Scenario: minimalistic\n" +
                "    Given the minimalism\n", "test.feature");
        List<Envelope> envelopes = Gherkin.fromSources(singletonList(envelope), false, true, false).collect(Collectors.toList());

        GherkinDocument gherkinDocument = envelopes.get(0).getGherkinDocument();
        GherkinDocument.Feature feature = gherkinDocument.getFeature();
        assertEquals("Minimal", feature.getName());
    }
}

@@ -251,16 +251,48 @@
 lectors;
+%0Aimport java.util.stream.Stream;
 %0A%0Aimport
@@ -501,51 +501,235 @@
 oid 
-provides_access_to_the_ast() %7B%0A        List
+use_this_in_readme() %7B%0A        List%3CString%3E paths = singletonList(%22testdata/good/minimal.feature%22);%0A        boolean includeSource = false;%0A        boolean includeAst = true;%0A        boolean includePickles = true;%0A        Stream
 %3CEnv
@@ -735,33 +735,38 @@
 velope%3E envelope
-s
+Stream
  = Gherkin.fromP
@@ -774,74 +774,611 @@
 ths(
-singletonList(%22testdata/good/minimal.feature%22), false, true, false
+paths, includeSource, includeAst, includePickles);%0A        Stream%3CEnvelope%3E pickleStream = envelopeStream.filter(Envelope::hasPickle);%0A%0A        assertEquals(%22minimalistic%22, pickleStream.collect(Collectors.toList()).get(0).getPickle().getName());%0A    %7D%0A%0A%0A    @Test%0A    public void provides_access_to_the_ast() %7B%0A        List%3CString%3E paths = singletonList(%22testdata/good/minimal.feature%22);%0A        boolean includeSource = false;%0A        boolean includeAst = true;%0A        boolean includePickles = false;%0A        List%3CEnvelope%3E envelopes = Gherkin.fromPaths(paths, includeSource, includeAst, includePickles
 ).co

Update README for Java