Search in sources :

Example 6 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method can_have_doc_string_as_last_argument_among_many.

@Test
public void can_have_doc_string_as_last_argument_among_many() throws Throwable {
    StepDefinition stepDefinition = mock(StepDefinition.class);
    when(stepDefinition.getParameterCount()).thenReturn(2);
    when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Integer.TYPE, null, null, null));
    when(stepDefinition.getParameterType(1, String.class)).thenReturn(new ParameterInfo(String.class, null, null, null));
    Step stepWithDocString = mock(Step.class);
    DocString docString = new DocString("test", "HELLO", 999);
    when(stepWithDocString.getDocString()).thenReturn(docString);
    when(stepWithDocString.getRows()).thenReturn(null);
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(Arrays.asList(new Argument(0, "5")), stepDefinition, "some.feature", stepWithDocString, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(ENGLISH);
    verify(stepDefinition).execute(ENGLISH, new Object[] { 5, "HELLO" });
}
Also used : Argument(gherkin.formatter.Argument) DocString(gherkin.formatter.model.DocString) DocString(gherkin.formatter.model.DocString) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

Example 7 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method converts_doc_string_with_explicit_converter.

@Test
public void converts_doc_string_with_explicit_converter() throws Throwable {
    StepDefinition stepDefinition = mock(StepDefinition.class);
    when(stepDefinition.getParameterCount()).thenReturn(1);
    when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Thing.class, null, null, null));
    Step stepWithDocString = mock(Step.class);
    DocString docString = new DocString("test", "the thing", 999);
    when(stepWithDocString.getDocString()).thenReturn(docString);
    when(stepWithDocString.getRows()).thenReturn(null);
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(new ArrayList<Argument>(), stepDefinition, "some.feature", stepWithDocString, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(ENGLISH);
    verify(stepDefinition).execute(ENGLISH, new Object[] { new Thing("the thing") });
}
Also used : Argument(gherkin.formatter.Argument) DocString(gherkin.formatter.model.DocString) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

Example 8 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method can_have_doc_string_as_only_argument.

@Test
public void can_have_doc_string_as_only_argument() throws Throwable {
    StepDefinition stepDefinition = mock(StepDefinition.class);
    when(stepDefinition.getParameterCount()).thenReturn(1);
    when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(String.class, null, null, null));
    Step stepWithDocString = mock(Step.class);
    DocString docString = new DocString("text/plain", "HELLO", 999);
    when(stepWithDocString.getDocString()).thenReturn(docString);
    when(stepWithDocString.getRows()).thenReturn(null);
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(new ArrayList<Argument>(), stepDefinition, "some.feature", stepWithDocString, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(ENGLISH);
    verify(stepDefinition).execute(ENGLISH, new Object[] { "HELLO" });
}
Also used : Argument(gherkin.formatter.Argument) DocString(gherkin.formatter.model.DocString) DocString(gherkin.formatter.model.DocString) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

Example 9 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class StepDefinitionMatchTest method converts_numbers.

@Test
public void converts_numbers() throws Throwable {
    StepDefinition stepDefinition = mock(StepDefinition.class);
    when(stepDefinition.getParameterCount()).thenReturn(1);
    when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Integer.TYPE, null, null, null));
    Step stepWithoutDocStringOrTable = mock(Step.class);
    when(stepWithoutDocStringOrTable.getDocString()).thenReturn(null);
    when(stepWithoutDocStringOrTable.getRows()).thenReturn(null);
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(Arrays.asList(new Argument(0, "5")), stepDefinition, "some.feature", stepWithoutDocStringOrTable, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(ENGLISH);
    verify(stepDefinition).execute(ENGLISH, new Object[] { 5 });
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

Example 10 with LocalizedXStreams

use of cucumber.runtime.xstream.LocalizedXStreams in project cucumber-jvm by cucumber.

the class DataTable method create.

private static DataTable create(List<?> raw, Locale locale, String format, String... columnNames) {
    ParameterInfo parameterInfo = new ParameterInfo(null, format, null, null);
    TableConverter tableConverter = new TableConverter(new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(locale), parameterInfo);
    return tableConverter.toTable(raw, columnNames);
}
Also used : TableConverter(cucumber.runtime.table.TableConverter) ParameterInfo(cucumber.runtime.ParameterInfo) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams)

Aggregations

LocalizedXStreams (cucumber.runtime.xstream.LocalizedXStreams)15 Test (org.junit.Test)10 Step (gherkin.formatter.model.Step)9 Argument (gherkin.formatter.Argument)8 I18n (gherkin.I18n)3 DataTableRow (gherkin.formatter.model.DataTableRow)3 DocString (gherkin.formatter.model.DocString)3 ArrayList (java.util.ArrayList)3 DataTable (cucumber.api.DataTable)2 ParameterInfo (cucumber.runtime.ParameterInfo)2 StepDefinition (cucumber.runtime.StepDefinition)1 StepDefinitionMatch (cucumber.runtime.StepDefinitionMatch)1 StubStepDefinition (cucumber.runtime.StubStepDefinition)1 TableConverter (cucumber.runtime.table.TableConverter)1 En (gherkin.lexer.En)1 Lexer (gherkin.lexer.Lexer)1 Listener (gherkin.lexer.Listener)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Before (org.junit.Before)1