Search in sources :

Example 11 with LocalizedXStreams

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

the class FromDataTableTest method runStepDef.

private StepDefs runStepDef(Method method, List<DataTableRow> rows) throws Throwable {
    StepDefs stepDefs = new StepDefs();
    StepDefinition stepDefinition = new StubStepDefinition(stepDefs, method, "some pattern");
    Step stepWithRows = new Step(NO_COMMENTS, "Given ", "something", 10, rows, null);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    StepDefinitionMatch stepDefinitionMatch = new StepDefinitionMatch(NO_ARGS, stepDefinition, "some.feature", stepWithRows, new LocalizedXStreams(classLoader));
    stepDefinitionMatch.runStep(new I18n("en"));
    return stepDefs;
}
Also used : StubStepDefinition(cucumber.runtime.StubStepDefinition) StepDefinition(cucumber.runtime.StepDefinition) StubStepDefinition(cucumber.runtime.StubStepDefinition) Step(gherkin.formatter.model.Step) StepDefinitionMatch(cucumber.runtime.StepDefinitionMatch) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) I18n(gherkin.I18n)

Example 12 with LocalizedXStreams

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

the class TableParser method parse.

public static DataTable parse(String source, ParameterInfo parameterInfo) {
    final List<DataTableRow> rows = new ArrayList<DataTableRow>();
    Lexer l = new En(new Listener() {

        @Override
        public void comment(String comment, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void tag(String tag, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void feature(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void background(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void scenario(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void scenarioOutline(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void examples(String keyword, String name, String description, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void step(String keyword, String name, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void row(List<String> cells, Integer line) {
            rows.add(new DataTableRow(NO_COMMENTS, cells, line));
        }

        @Override
        public void docString(String contentType, String string, Integer line) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void eof() {
        }
    });
    l.scan(source);
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    return new DataTable(rows, new TableConverter(new LocalizedXStreams(classLoader).get(Locale.US), parameterInfo));
}
Also used : DataTable(cucumber.api.DataTable) Listener(gherkin.lexer.Listener) ArrayList(java.util.ArrayList) En(gherkin.lexer.En) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Lexer(gherkin.lexer.Lexer) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 13 with LocalizedXStreams

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

the class ToDataTableTest method createTableConverterWithDateFormat.

@Before
public void createTableConverterWithDateFormat() {
    LocalizedXStreams.LocalizedXStream xStream = new LocalizedXStreams(Thread.currentThread().getContextClassLoader()).get(Locale.US);
    tc = new TableConverter(xStream, new ParameterInfo(null, DD_MM_YYYY, null, null));
}
Also used : ParameterInfo(cucumber.runtime.ParameterInfo) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Before(org.junit.Before)

Example 14 with LocalizedXStreams

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

the class DataTableTest method createTable.

private DataTable createTable(List<String>... rows) {
    List<DataTableRow> simpleRows = new ArrayList<DataTableRow>();
    for (int i = 0; i < rows.length; i++) {
        simpleRows.add(new DataTableRow(new ArrayList<Comment>(), rows[i], i + 1));
    }
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    LocalizedXStreams.LocalizedXStream xStream = new LocalizedXStreams(classLoader).get(Locale.US);
    return new DataTable(simpleRows, new TableConverter(xStream, null));
}
Also used : DataTable(cucumber.api.DataTable) ArrayList(java.util.ArrayList) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) DataTableRow(gherkin.formatter.model.DataTableRow)

Example 15 with LocalizedXStreams

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

the class StepDefinitionMatchTest method gives_nice_error_message_when_conversion_fails.

@Test
public void gives_nice_error_message_when_conversion_fails() throws Throwable {
    StepDefinition stepDefinition = mock(StepDefinition.class);
    when(stepDefinition.getParameterCount()).thenReturn(1);
    when(stepDefinition.getParameterType(0, String.class)).thenReturn(new ParameterInfo(Thang.class, 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, "blah")), stepDefinition, "some.feature", stepWithoutDocStringOrTable, new LocalizedXStreams(classLoader));
    try {
        stepDefinitionMatch.runStep(ENGLISH);
        fail();
    } catch (CucumberException expected) {
        assertEquals("Don't know how to convert \"blah\" into cucumber.runtime.StepDefinitionMatchTest$Thang.\n" + "Try writing your own converter:\n" + "\n" + "@cucumber.deps.com.thoughtworks.xstream.annotations.XStreamConverter(ThangConverter.class)\n" + "public class Thang {}\n", expected.getMessage());
    }
}
Also used : Argument(gherkin.formatter.Argument) Step(gherkin.formatter.model.Step) LocalizedXStreams(cucumber.runtime.xstream.LocalizedXStreams) Test(org.junit.Test)

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