use of io.cucumber.docstring.DocString 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.DocString in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method docstring_expression_transform_doc_string_to_string.
@Test
void docstring_expression_transform_doc_string_to_string() {
String docString = "A rather long and boring string of documentation";
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", String.class);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", docString, null);
assertThat(match.get(0).getValue(), is(equalTo(docString)));
}
use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method unknown_target_type_transform_doc_string_to_doc_string.
@Test
void unknown_target_type_transform_doc_string_to_doc_string() {
String docString = "A rather long and boring string of documentation";
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", docString, null);
assertThat(match.get(0).getValue(), is(equalTo(DocString.create(docString))));
}
use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.
the class StepExpressionFactoryTest method docstring_and_datatable_match_same_step_definition.
@Test
void docstring_and_datatable_match_same_step_definition() {
String docString = "A rather long and boring string of documentation";
StepDefinition stepDefinition = new StubStepDefinition("Given some stuff:", UNKNOWN_TYPE);
StepExpression expression = stepExpressionFactory.createExpression(stepDefinition);
List<Argument> match = expression.match("Given some stuff:", docString, null);
assertThat(match.get(0).getValue(), is(equalTo(DocString.create(docString))));
match = expression.match("Given some stuff:", table);
assertThat(match.get(0).getValue(), is(equalTo(DataTable.create(table))));
}
use of io.cucumber.docstring.DocString in project cucumber-jvm by cucumber.
the class JavaDocStringTypeDefinitionTest method correct_conversion_is_used_for_simple_and_complex_return_types.
@Test
public void correct_conversion_is_used_for_simple_and_complex_return_types() throws NoSuchMethodException {
Method simpleMethod = JavaDocStringTypeDefinitionTest.class.getMethod("converts_string_to_simple_type", String.class);
JavaDocStringTypeDefinition simpleDefinition = new JavaDocStringTypeDefinition("text/plain", simpleMethod, lookup);
registry.defineDocStringType(simpleDefinition.docStringType());
Method complexMethod = JavaDocStringTypeDefinitionTest.class.getMethod("converts_string_to_complex_type", String.class);
JavaDocStringTypeDefinition complexDefinition = new JavaDocStringTypeDefinition("text/plain", complexMethod, lookup);
registry.defineDocStringType(complexDefinition.docStringType());
Type simpleType = Map.class;
assertThat(converter.convert(docString, simpleType), hasEntry("some_simple_type", Collections.emptyMap()));
Type complexType = new TypeReference<Map<String, Map<String, String>>>() {
}.getType();
assertThat(converter.convert(docString, complexType), hasEntry("some_complex_type", Collections.emptyMap()));
}
Aggregations