Search in sources :

Example 1 with Argument

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")));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 2 with Argument

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"));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 3 with Argument

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"));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 4 with Argument

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"));
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 5 with Argument

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());
}
Also used : ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Argument(io.cucumber.cucumberexpressions.Argument) Expression(io.cucumber.cucumberexpressions.Expression) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Aggregations

Argument (io.cucumber.cucumberexpressions.Argument)5 Expression (io.cucumber.cucumberexpressions.Expression)5 ExpressionFactory (io.cucumber.cucumberexpressions.ExpressionFactory)5 Method (java.lang.reflect.Method)5 Test (org.junit.jupiter.api.Test)5