use of io.cucumber.docstring.DocStringType in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method throws_could_not_convert_exception_for_docstring.
@Test
void throws_could_not_convert_exception_for_docstring() {
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n" + " \"\"\"doc\n" + " converting this should throw an exception\n" + " \"\"\"\n");
stepTypeRegistry.defineDocStringType(new DocStringType(ItemQuantity.class, "doc", content -> {
throw new IllegalArgumentException(content);
}));
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.docstring.DocStringType in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method docstring_expression_transform_doc_string_to_json_node.
@Test
void docstring_expression_transform_doc_string_to_json_node() {
String docString = "{\"hello\": \"world\"}";
String contentType = "json";
registry.defineDocStringType(new DocStringType(JsonNode.class, contentType, (String s) -> objectMapper.convertValue(docString, JsonNode.class)));
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", JsonNode.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", docString, contentType);
JsonNode node = (JsonNode) match.get(0).getValue();
assertThat(node.asText(), equalTo(docString));
}
use of io.cucumber.docstring.DocStringType in project cucumber-jvm by cucumber.
the class StepDefinitionMatchTest method rethrows_target_invocation_exception_for_docstring.
@Test
void rethrows_target_invocation_exception_for_docstring() {
RuntimeException userException = new RuntimeException();
Feature feature = TestFeatureParser.parse("" + "Feature: Test feature\n" + " Scenario: Test scenario\n" + " Given I have some cukes in my belly\n" + " \"\"\"doc\n" + " converting this should throw an exception\n" + " \"\"\"\n");
stepTypeRegistry.defineDocStringType(new DocStringType(ItemQuantity.class, "doc", content -> {
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.docstring.DocStringType in project cucumber-jvm by cucumber.
the class StepTypeRegistryTest method should_define_doc_string_parameter_type.
@Test
void should_define_doc_string_parameter_type() {
DocStringType expected = new DocStringType(JsonNode.class, "json", (String s) -> null);
registry.defineDocStringType(expected);
}
Aggregations