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}'.")));
}
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)));
}
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")));
}
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));
}
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);
}
Aggregations