use of io.cucumber.cucumberexpressions.Argument in project cucumber-jvm by cucumber.
the class JavaParameterTypeDefinitionTest method converter_may_have_non_generic_return_type.
@Test
void converter_may_have_non_generic_return_type() throws NoSuchMethodException {
Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_capture_group_to_optional_string", String.class);
JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "(.*)", method, false, false, false, lookup);
registry.defineParameterType(definition.parameterType());
Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_capture_group_to_optional_string}");
List<Argument<?>> args = cucumberExpression.match("convert_capture_group_to_optional_string");
assertThat(args.get(0).getValue(), is(Optional.of("convert_capture_group_to_optional_string")));
}
use of io.cucumber.cucumberexpressions.Argument in project cucumber-jvm by cucumber.
the class JavaParameterTypeDefinitionTest method can_define_parameter_type_converters_with_two_capture_groups.
@Test
void can_define_parameter_type_converters_with_two_capture_groups() throws NoSuchMethodException {
Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_two_capture_group_to_string", String.class, String.class);
JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "([^ ]*) ([^ ]*)", method, false, false, false, lookup);
registry.defineParameterType(definition.parameterType());
Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_two_capture_group_to_string}");
List<Argument<?>> test = cucumberExpression.match("test test");
assertThat(test.get(0).getValue(), equalTo("convert_two_capture_group_to_string"));
}
use of io.cucumber.cucumberexpressions.Argument in project cucumber-jvm by cucumber.
the class JavaParameterTypeDefinitionTest method can_define_parameter_type_converters_with_one_capture_group.
@Test
void can_define_parameter_type_converters_with_one_capture_group() throws NoSuchMethodException {
Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_one_capture_group_to_string", String.class);
JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "(.*)", method, false, false, false, lookup);
registry.defineParameterType(definition.parameterType());
Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_one_capture_group_to_string}");
List<Argument<?>> test = cucumberExpression.match("test");
assertThat(test.get(0).getValue(), equalTo("convert_one_capture_group_to_string"));
}
use of io.cucumber.cucumberexpressions.Argument in project cucumber-jvm by cucumber.
the class JavaParameterTypeDefinitionTest method can_define_parameter_type_converters_with_var_args.
@Test
void can_define_parameter_type_converters_with_var_args() throws NoSuchMethodException {
Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_varargs_capture_group_to_string", String[].class);
JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", "([^ ]*) ([^ ]*)", method, false, false, false, lookup);
registry.defineParameterType(definition.parameterType());
Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_varargs_capture_group_to_string}");
List<Argument<?>> test = cucumberExpression.match("test test");
assertThat(test.get(0).getValue(), equalTo("convert_varargs_capture_group_to_string"));
}
use of io.cucumber.cucumberexpressions.Argument in project cucumber-jvm by cucumber.
the class JavaParameterTypeDefinitionTest method arguments_must_match_captured_groups.
@Test
void arguments_must_match_captured_groups() throws NoSuchMethodException {
Method method = JavaParameterTypeDefinitionTest.class.getMethod("convert_two_capture_group_to_string", String.class, String.class);
JavaParameterTypeDefinition definition = new JavaParameterTypeDefinition("", ".*", method, false, false, false, lookup);
registry.defineParameterType(definition.parameterType());
Expression cucumberExpression = new ExpressionFactory(registry).createExpression("{convert_two_capture_group_to_string}");
List<Argument<?>> test = cucumberExpression.match("test");
assertThrows(CucumberExpressionException.class, () -> test.get(0).getValue());
}
Aggregations