package io.cucumber.java8;

import gherkin.pickles.Argument;
import gherkin.pickles.PickleLocation;
import gherkin.pickles.PickleStep;
import io.cucumber.core.snippets.SnippetGenerator;
import io.cucumber.core.snippets.SnippetType;
import io.cucumber.cucumberexpressions.ParameterTypeRegistry;
import org.junit.jupiter.api.Test;

import java.util.Collections;
import java.util.Locale;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;

public class Java8SnippetTest {

    private static final String GIVEN_KEYWORD = "Given";

    @Test
    public void generatesPlainSnippet() {
        String expected = "" +
            "Given(\"I have {int} cukes in my {string} belly\", (Integer int1, String string) -> {\n" +
            "    // Write code here that turns the phrase above into concrete actions\n" +
            "    throw new io.cucumber.java8.PendingException();\n" +
            "});\n";
        System.out.println(expected);
        assertThat(snippetFor("I have 4 cukes in my \"big\" belly"), is(equalTo(expected)));
    }

    private String snippetFor(String name) {
        PickleStep step = new PickleStep(name, Collections.<Argument>emptyList(), Collections.<PickleLocation>emptyList());
        return String.join(
            "\n",
            new SnippetGenerator(
                new Java8Snippet(),
                new ParameterTypeRegistry(Locale.ENGLISH)).getSnippet(step, GIVEN_KEYWORD, SnippetType.UNDERSCORE)
        );
    }

}

@@ -83,24 +83,20 @@
 s.Pickle
-Location
+Step
 ;%0Aimport
@@ -110,36 +110,37 @@
 n.pickles.Pickle
-Step
+Table
 ;%0Aimport io.cucu
@@ -350,16 +350,39 @@
 ctions;%0A
+import java.util.List;%0A
 import j
@@ -1013,26 +1013,45 @@
     
-System.out.println
+assertThat(plainSnippet(), is(equalTo
 (exp
@@ -1060,48 +1060,134 @@
 ted)
+))
 ;%0A    
+%7D%0A%0A
     
-assertThat(snippetFor(
+@Test%0A    public void generatesDataTableSnippet() %7B%0A        String expected = %22%22 +%0A            %22Given(%5C
 %22I have 
 4 cu
@@ -1186,9 +1186,13 @@
 ave 
-4
+%7Bint%7D
  cuk
@@ -1204,211 +1204,1185 @@
  my 
-%5C%22big%5C%22 belly%22), is(equalTo(expected)));%0A    %7D%0A%0A    private String snippetFor(String name) %7B%0A        PickleStep step = new PickleStep(name, Collections.%3CArgument%3EemptyList(), Collections.%3CPickleLocation%3E
+%7Bstring%7D belly%5C%22, (Integer int1, String string, io.cucumber.datatable.DataTable dataTable) -%3E %7B%5Cn%22 +%0A            %22    // Write code here that turns the phrase above into concrete actions%5Cn%22 +%0A            %22    // For automatic transformation, change DataTable to one of%5Cn%22 +%0A            %22    // E, List%3CE%3E, List%3CList%3CE%3E%3E, List%3CMap%3CK,V%3E%3E, Map%3CK,V%3E or%5Cn%22 +%0A            %22    // Map%3CK, List%3CV%3E%3E. E,K,V must be a String, Integer, Float,%5Cn%22 +%0A            %22    // Double, Byte, Short, Long, BigInteger or BigDecimal.%5Cn%22 +%0A            %22    //%5Cn%22 +%0A            %22    // For other transformations you can register a DataTableType.%5Cn%22 +%0A            %22    throw new io.cucumber.java8.PendingException();%5Cn%22 +%0A            %22%7D);%5Cn%22;%0A        assertThat(dataTableSnippet(), is(equalTo(expected)));%0A    %7D%0A%0A    private String plainSnippet() %7B%0A        return snippet2(Collections.emptyList());%0A    %7D%0A%0A    private String dataTableSnippet() %7B%0A        return snippet2(Collections.singletonList(new PickleTable(Collections.emptyList())));%0A    %7D%0A%0A    private String snippet2(List%3CArgument%3E arguments) %7B%0A        PickleStep step = new PickleStep(%22I have 4 cukes in my %5C%22big%5C%22 belly%22, arguments, Collections.
 empt

Improve test coverage