Search in sources :

Example 6 with Expression

use of io.cucumber.cucumberexpressions.Expression 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)

Example 7 with Expression

use of io.cucumber.cucumberexpressions.Expression in project cucumber-jvm by cucumber.

the class StepExpressionFactory method createExpression.

private StepExpression createExpression(String expressionString, Supplier<Type> tableOrDocStringType, boolean transpose) {
    requireNonNull(expressionString, "expressionString can not be null");
    requireNonNull(tableOrDocStringType, "tableOrDocStringType can not be null");
    final Expression expression = crateExpression(expressionString);
    RawTableTransformer<?> tableTransform = (List<List<String>> raw) -> {
        DataTable dataTable = DataTable.create(raw, StepExpressionFactory.this.tableConverter);
        Type targetType = tableOrDocStringType.get();
        return dataTable.convert(Object.class.equals(targetType) ? DataTable.class : targetType, transpose);
    };
    DocStringTransformer<?> docStringTransform = (text, contentType) -> {
        DocString docString = DocString.create(text, contentType, docStringConverter);
        Type targetType = tableOrDocStringType.get();
        return docString.convert(Object.class.equals(targetType) ? DocString.class : targetType);
    };
    return new StepExpression(expression, docStringTransform, tableTransform);
}
Also used : UndefinedParameterTypeException(io.cucumber.cucumberexpressions.UndefinedParameterTypeException) DocString(io.cucumber.docstring.DocString) Envelope(io.cucumber.messages.types.Envelope) DocStringTypeRegistryDocStringConverter(io.cucumber.docstring.DocStringTypeRegistryDocStringConverter) UndefinedParameterType(io.cucumber.messages.types.UndefinedParameterType) Expression(io.cucumber.cucumberexpressions.Expression) Supplier(java.util.function.Supplier) String.format(java.lang.String.format) StepDefinition(io.cucumber.core.backend.StepDefinition) List(java.util.List) ParameterInfo(io.cucumber.core.backend.ParameterInfo) ExpressionFactory(io.cucumber.cucumberexpressions.ExpressionFactory) Type(java.lang.reflect.Type) Objects.requireNonNull(java.util.Objects.requireNonNull) DataTableTypeRegistryTableConverter(io.cucumber.datatable.DataTableTypeRegistryTableConverter) CucumberException(io.cucumber.core.exception.CucumberException) DataTable(io.cucumber.datatable.DataTable) EventBus(io.cucumber.core.eventbus.EventBus) DataTable(io.cucumber.datatable.DataTable) UndefinedParameterType(io.cucumber.messages.types.UndefinedParameterType) Type(java.lang.reflect.Type) Expression(io.cucumber.cucumberexpressions.Expression) List(java.util.List) DocString(io.cucumber.docstring.DocString)

Aggregations

Expression (io.cucumber.cucumberexpressions.Expression)7 ExpressionFactory (io.cucumber.cucumberexpressions.ExpressionFactory)6 Test (org.junit.jupiter.api.Test)6 Argument (io.cucumber.cucumberexpressions.Argument)5 Method (java.lang.reflect.Method)5 ParameterInfo (io.cucumber.core.backend.ParameterInfo)1 StepDefinition (io.cucumber.core.backend.StepDefinition)1 EventBus (io.cucumber.core.eventbus.EventBus)1 CucumberException (io.cucumber.core.exception.CucumberException)1 ParameterType (io.cucumber.cucumberexpressions.ParameterType)1 UndefinedParameterTypeException (io.cucumber.cucumberexpressions.UndefinedParameterTypeException)1 DataTable (io.cucumber.datatable.DataTable)1 DataTableTypeRegistryTableConverter (io.cucumber.datatable.DataTableTypeRegistryTableConverter)1 DocString (io.cucumber.docstring.DocString)1 DocStringTypeRegistryDocStringConverter (io.cucumber.docstring.DocStringTypeRegistryDocStringConverter)1 Envelope (io.cucumber.messages.types.Envelope)1 UndefinedParameterType (io.cucumber.messages.types.UndefinedParameterType)1 String.format (java.lang.String.format)1 Type (java.lang.reflect.Type)1 List (java.util.List)1