use of io.cucumber.core.gherkin.Step 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.core.gherkin.Step in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table.
@Test
void throws_arity_mismatch_exception_when_there_are_fewer_parameters_than_arguments_with_data_table() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have 4 cukes in my belly\n" + " | A | B | \n" + " | C | D | \n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have {int} cukes in my belly");
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
PickleStepDefinitionMatch stepDefinitionMatch = new PickleStepDefinitionMatch(arguments, stepDefinition, null, step);
Executable testMethod = () -> stepDefinitionMatch.runStep(null);
CucumberException actualThrown = assertThrows(CucumberException.class, testMethod);
assertThat("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Step [I have {int} cukes in my belly] is defined with 0 parameters at '{stubbed location with details}'.\n" + "However, the gherkin step has 2 arguments:\n" + " * 4\n" + " * Table:\n" + " | A | B |\n" + " | C | D |\n" + "\n" + "Step text: I have 4 cukes in my belly")));
}
use of io.cucumber.core.gherkin.Step in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch.
@Test
void throws_could_not_convert_exception_for_transformer_and_capture_group_mismatch() {
stepTypeRegistry.defineParameterType(new ParameterType<>("itemQuantity", "(few|some|lots of) (cukes|gherkins)", ItemQuantity.class, // Wrong number of capture groups
(String s) -> null));
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have {itemQuantity} 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("Unexpected exception message", actualThrown.getMessage(), is(equalTo("Could not convert arguments for step [I have {itemQuantity} in my belly] defined at '{stubbed location with details}'.")));
}
use of io.cucumber.core.gherkin.Step in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method rethrows_target_invocation_exceptions_from_parameter_type.
@Test
void rethrows_target_invocation_exceptions_from_parameter_type() {
RuntimeException userException = new RuntimeException();
stepTypeRegistry.defineParameterType(new ParameterType<>("itemQuantity", "(few|some|lots of) (cukes|gherkins)", ItemQuantity.class, (String[] s) -> {
throw new CucumberInvocationTargetException(stubbedLocation, new InvocationTargetException(userException));
}));
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n");
Step step = feature.getPickles().get(0).getSteps().get(0);
StepDefinition stepDefinition = new StubStepDefinition("I have {itemQuantity} 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.core.gherkin.Step in project cucumber-jvm by cucumber.
the class CoreStepDefinitionTest method runStepDef.
@SuppressWarnings("unchecked")
private <T> T runStepDef(Method method, boolean transposed, Feature feature) {
StubStepDefinition stepDefinition = new StubStepDefinition("some text", transposed, method.getGenericParameterTypes());
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
Step stepWithTable = feature.getPickles().get(0).getSteps().get(0);
List<Argument> arguments = coreStepDefinition.matchedArguments(stepWithTable);
List<Object> result = new ArrayList<>();
for (Argument argument : arguments) {
result.add(argument.getValue());
}
coreStepDefinition.getStepDefinition().execute(result.toArray(new Object[0]));
return (T) stepDefinition.getArgs().get(0);
}
Aggregations