Search in sources :

Example 1 with DataTableType

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

the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_singleton_table_dimension_mismatch.

@Test
void throws_could_not_convert_exception_for_singleton_table_dimension_mismatch() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some cukes in my belly\n" + "       | 3 | \n" + "       | 14 | \n" + "       | 15 | \n");
    stepTypeRegistry.defineDataTableType(new DataTableType(ItemQuantity.class, ItemQuantity::new));
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have some cukes in my belly", ItemQuantity.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(step);
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
    assertThat(actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have some cukes in my belly] defined at '{stubbed location with details}'.")));
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) Argument(io.cucumber.core.stepexpression.Argument) Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) CucumberException(io.cucumber.core.exception.CucumberException) Executable(org.junit.jupiter.api.function.Executable) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 2 with DataTableType

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

the class StepExpressionFactoryTest method table_expression_with_list_type_creates_list_of_ingredients_from_table.

@SuppressWarnings("unchecked")
@Test
void table_expression_with_list_type_creates_list_of_ingredients_from_table() {
    registry.defineDataTableType(new DataTableType(Ingredient.class, listBeanMapper(registry)));
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", getTypeFromStepDefinition());
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", table);
    List<Ingredient> ingredients = (List<Ingredient>) match.get(0).getValue();
    Ingredient ingredient = ingredients.get(0);
    assertThat(ingredient.amount, is(equalTo(2)));
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 3 with DataTableType

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

the class StepExpressionFactoryTest method table_expression_with_type_creates_single_ingredients_from_table.

@Test
void table_expression_with_type_creates_single_ingredients_from_table() {
    registry.defineDataTableType(new DataTableType(Ingredient.class, beanMapper(registry)));
    StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", Ingredient.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    List<Argument> match = expression.match("Given some stuff:", tableTransposed);
    Ingredient ingredient = (Ingredient) match.get(0).getValue();
    assertThat(ingredient.name, is(equalTo("chocolate")));
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) 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 4 with DataTableType

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

the class StepDefinitionMatchTest method rethrows_target_invocation_exceptions_from_data_table.

@Test
void rethrows_target_invocation_exceptions_from_data_table() {
    Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + "  Scenario: Test scenario\n" + "     Given I have some cukes in my belly\n" + "       | 3 | \n" + "       | 14 | \n" + "       | 15 | \n");
    RuntimeException userException = new RuntimeException();
    stepTypeRegistry.defineDataTableType(new DataTableType(ItemQuantity.class, (String cell) -> {
        throw new CucumberInvocationTargetException(stubbedLocation, new InvocationTargetException(userException));
    }));
    Step step = feature.getPickles().get(0).getSteps().get(0);
    StepDefinition stepDefinition = new StubStepDefinition("I have some cukes in my belly", ItemQuantity.class);
    StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
    CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
    List<Argument> arguments = coreStepDefinition.matchedArguments(step);
    StepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
    Executable testMethod = () -> stepDefinitionMatch.runStep(null);
    RuntimeException actualThrown = assertThrows(RuntimeException.class, testMethod);
    assertThat(actualThrown, sameInstance(userException));
}
Also used : DataTableType(io.cucumber.datatable.DataTableType) Argument(io.cucumber.core.stepexpression.Argument) Step(io.cucumber.core.gherkin.Step) Feature(io.cucumber.core.gherkin.Feature) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CucumberInvocationTargetException(io.cucumber.core.backend.CucumberInvocationTargetException) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) StepDefinition(io.cucumber.core.backend.StepDefinition) StubStepDefinition(io.cucumber.core.backend.StubStepDefinition) Executable(org.junit.jupiter.api.function.Executable) StepExpression(io.cucumber.core.stepexpression.StepExpression) Test(org.junit.jupiter.api.Test)

Example 5 with DataTableType

use of io.cucumber.datatable.DataTableType 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)

Aggregations

DataTableType (io.cucumber.datatable.DataTableType)6 Test (org.junit.jupiter.api.Test)5 StepDefinition (io.cucumber.core.backend.StepDefinition)4 StubStepDefinition (io.cucumber.core.backend.StubStepDefinition)4 Feature (io.cucumber.core.gherkin.Feature)2 Step (io.cucumber.core.gherkin.Step)2 Argument (io.cucumber.core.stepexpression.Argument)2 StepExpression (io.cucumber.core.stepexpression.StepExpression)2 DataTable (io.cucumber.datatable.DataTable)2 List (java.util.List)2 Executable (org.junit.jupiter.api.function.Executable)2 CucumberInvocationTargetException (io.cucumber.core.backend.CucumberInvocationTargetException)1 CucumberException (io.cucumber.core.exception.CucumberException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptyList (java.util.Collections.emptyList)1 Map (java.util.Map)1