Search in sources :

Example 1 with DataTable

use of io.cucumber.datatable.DataTable in project cucumber-jvm by cucumber.

the class StepExpressionFactoryTest method table_expression_with_type_creates_table_from_table.

@Test
void table_expression_with_type_creates_table_from_table() {
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", DataTable.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", table);
    DataTable dataTable = (DataTable) match.get(0).getValue();
    assertThat(dataTable.cells(), is(equalTo(table)));
}
Also used : DataTable(io.cucumber.datatable.DataTable) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with DataTable

use of io.cucumber.datatable.DataTable in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method passes_transposed_data_table.

@Test
void passes_transposed_data_table() throws Throwable {
    Method m = Steps.class.getMethod("plainDataTable", DataTable.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | Birth Date | \n" + "      | 1957-05-10 | \n");
    DataTable stepDefs = runStepDef(m, true, feature);
    assertAll(() -> assertThat(stepDefs.cell(0, 0), is(equalTo("Birth Date"))), () -> assertThat(stepDefs.cell(0, 1), is(equalTo("1957-05-10"))));
}
Also used : DataTable(io.cucumber.datatable.DataTable) Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 3 with DataTable

use of io.cucumber.datatable.DataTable in project cucumber-jvm by cucumber.

the class CoreStepDefinitionTest method passes_plain_data_table.

@Test
void passes_plain_data_table() throws Throwable {
    Method m = Steps.class.getMethod("plainDataTable", DataTable.class);
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given some text\n" + "      | Birth Date | \n" + "      | 1957-05-10 | \n");
    DataTable stepDefs = runStepDef(m, false, feature);
    assertAll(() -> assertThat(stepDefs.cell(0, 0), is(equalTo("Birth Date"))), () -> assertThat(stepDefs.cell(1, 0), is(equalTo("1957-05-10"))));
}
Also used : DataTable(io.cucumber.datatable.DataTable) Method(java.lang.reflect.Method) Feature(io.cucumber.core.gherkin.Feature) Test(org.junit.jupiter.api.Test)

Example 4 with DataTable

use of io.cucumber.datatable.DataTable in project cucumber-jvm by cucumber.

the class StepTypeRegistryTest method should_define_data_table_parameter_type.

@Test
void should_define_data_table_parameter_type() {
    DataTableType expected = new DataTableType(Date.class, (DataTable dataTable) -> null);
    registry.defineDataTableType(expected);
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) DataTable(io.cucumber.datatable.DataTable) Test(org.junit.jupiter.api.Test)

Example 5 with DataTable

use of io.cucumber.datatable.DataTable in project cucumber-jvm by cucumber.

the class StepExpressionFactory method createExpression.

private StepExpression createExpression(String expressionString, Supplier<Type> tableOrDocStringType, boolean transpose) {
    requireNonNull(expressionString, "expressionString can not be null");
    requireNonNull(tableOrDocStringType, "tableOrDocStringType can not be null");
    final Expression expression = crateExpression(expressionString);
    RawTableTransformer<?> tableTransform = (List<List<String>> raw) -> {
        DataTable dataTable = DataTable.create(raw, StepExpressionFactory.this.tableConverter);
        Type targetType = tableOrDocStringType.get();
        return dataTable.convert(Object.class.equals(targetType) ? DataTable.class : targetType, transpose);
    };
    DocStringTransformer<?> docStringTransform = (text, contentType) -> {
        DocString docString = DocString.create(text, contentType, docStringConverter);
        Type targetType = tableOrDocStringType.get();
        return docString.convert(Object.class.equals(targetType) ? DocString.class : targetType);
    };
    return new StepExpression(expression, docStringTransform, tableTransform);
}
Also used : UndefinedParameterTypeException(io.cucumber.cucumberexpressions.UndefinedParameterTypeException) DocString(io.cucumber.docstring.DocString) Envelope(io.cucumber.messages.types.Envelope) DocStringTypeRegistryDocStringConverter(io.cucumber.docstring.DocStringTypeRegistryDocStringConverter) UndefinedParameterType(io.cucumber.messages.types.UndefinedParameterType) Expression(io.cucumber.cucumberexpressions.Expression) Supplier(java.util.function.Supplier) String.format(java.lang.String.format) StepDefinition(io.cucumber.core.backend.StepDefinition) List(java.util.List) ParameterInfo(io.cucumber.core.backend.ParameterInfo) ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Type(java.lang.reflect.Type) Objects.requireNonNull(java.util.Objects.requireNonNull) DataTableTypeRegistryTableConverter(io.cucumber.datatable.DataTableTypeRegistryTableConverter) CucumberException(io.cucumber.core.exception.CucumberException) DataTable(io.cucumber.datatable.DataTable) EventBus(io.cucumber.core.eventbus.EventBus) DataTable(io.cucumber.datatable.DataTable) UndefinedParameterType(io.cucumber.messages.types.UndefinedParameterType) Type(java.lang.reflect.Type) Expression(io.cucumber.cucumberexpressions.Expression) List(java.util.List) DocString(io.cucumber.docstring.DocString)

Aggregations

DataTable (io.cucumber.datatable.DataTable)11 List (java.util.List)5 Test (org.junit.jupiter.api.Test)4 Then (io.cucumber.java.en.Then)3 When (io.cucumber.java.en.When)3 StepDefinition (io.cucumber.core.backend.StepDefinition)2 Feature (io.cucumber.core.gherkin.Feature)2 DataTableType (io.cucumber.datatable.DataTableType)2 Account (io.syndesis.qe.account.Account)2 Method (java.lang.reflect.Method)2 Type (java.lang.reflect.Type)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)1 EventBus (io.cucumber.core.eventbus.EventBus)1 CucumberException (io.cucumber.core.exception.CucumberException)1 Expression (io.cucumber.cucumberexpressions.Expression)1 ExpressionFactory (io.cucumber.cucumberexpressions.ExpressionFactory)1 UndefinedParameterTypeException (io.cucumber.cucumberexpressions.UndefinedParameterTypeException)1