use of io.cucumber.core.stepexpression.Argument 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.stepexpression.Argument 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.stepexpression.Argument 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);
}
use of io.cucumber.core.stepexpression.Argument in project cucumber-jvm by cucumber.
the class CoreStepDefinitionTest method should_apply_identity_transform_to_doc_string_when_target_type_is_object.
@Test
void should_apply_identity_transform_to_doc_string_when_target_type_is_object() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some step\n" + " \"\"\"\n" + " content\n" + " \"\"\"\n");
StepDefinition stepDefinition = new StubStepDefinition("I have some step", Object.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
CoreStepDefinition coreStepDefinition = new CoreStepDefinition(id, stepDefinition, expression);
Step step = feature.getPickles().get(0).getSteps().get(0);
List<Argument> arguments = coreStepDefinition.matchedArguments(step);
assertThat(arguments.get(0).getValue(), is(equalTo(DocString.create("content"))));
}
use of io.cucumber.core.stepexpression.Argument in project cucumber-jvm by cucumber.
the class PickleStepDefinitionMatch method runStep.
@Override
public void runStep(TestCaseState state) throws Throwable {
List<Argument> arguments = getArguments();
List<ParameterInfo> parameterInfos = stepDefinition.parameterInfos();
if (parameterInfos != null && arguments.size() != parameterInfos.size()) {
throw arityMismatch(parameterInfos.size());
}
List<Object> result = new ArrayList<>();
try {
for (Argument argument : arguments) {
result.add(argument.getValue());
}
} catch (UndefinedDataTableTypeException e) {
throw registerDataTableTypeInConfiguration(e);
} catch (CucumberExpressionException | CucumberDataTableException | CucumberDocStringException e) {
CucumberInvocationTargetException targetException;
if ((targetException = causedByCucumberInvocationTargetException(e)) != null) {
throw removeFrameworkFrames(targetException);
}
throw couldNotConvertArguments(e);
} catch (CucumberBackendException e) {
throw couldNotInvokeArgumentConversion(e);
} catch (CucumberInvocationTargetException e) {
throw removeFrameworkFrames(e);
}
try {
stepDefinition.execute(result.toArray(new Object[0]));
} catch (CucumberBackendException e) {
throw couldNotInvokeStep(e, result);
} catch (CucumberInvocationTargetException e) {
throw removeFrameworkFramesAndAppendStepLocation(e, getStepLocation());
}
}
Aggregations