Search in sources :

Example 1 with ParameterType

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

the class StepTypeRegistryTest method should_define_parameter_type.

@Test
void should_define_parameter_type() {
    ParameterType<Object> expected = new ParameterType<>("example", ".*", Object.class, (String s) -> null);
    registry.defineParameterType(expected);
    Expression expresion = expressionFactory.createExpression("{example}");
    assertThat(expresion.getRegexp().pattern(), is("^(.*)$"));
}
Also used : ParameterType(io.cucumber.cucumberexpressions.ParameterType) Expression(io.cucumber.cucumberexpressions.Expression) Test(org.junit.jupiter.api.Test)

Example 2 with ParameterType

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

the class SnippetGenerator method arguments.

private Map<String, Type> arguments(Step step, List<String> parameterNames, List<ParameterType<?>> parameterTypes) {
    Map<String, Type> arguments = new LinkedHashMap<>(parameterTypes.size() + 1);
    for (int i = 0; i < parameterTypes.size(); i++) {
        ParameterType<?> parameterType = parameterTypes.get(i);
        String parameterName = parameterNames.get(i);
        arguments.put(parameterName, parameterType.getType());
    }
    StepArgument arg = step.getArgument();
    if (arg == null) {
        return arguments;
    } else if (arg instanceof DocStringArgument) {
        arguments.put(parameterName("docString", parameterNames), String.class);
    } else if (arg instanceof DataTableArgument) {
        arguments.put(parameterName("dataTable", parameterNames), DataTable.class);
    }
    return arguments;
}
Also used : Type(java.lang.reflect.Type) ParameterType(io.cucumber.cucumberexpressions.ParameterType) StepArgument(io.cucumber.plugin.event.StepArgument) DataTableArgument(io.cucumber.plugin.event.DataTableArgument) LinkedHashMap(java.util.LinkedHashMap) DocStringArgument(io.cucumber.plugin.event.DocStringArgument)

Example 3 with ParameterType

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

the class CachingGlue method emitParameterTypeDefined.

private void emitParameterTypeDefined(ParameterType<?> parameterType) {
    io.cucumber.messages.types.ParameterType messagesParameterType = new io.cucumber.messages.types.ParameterType();
    messagesParameterType.setId(bus.generateId().toString());
    messagesParameterType.setName(parameterType.getName());
    messagesParameterType.setRegularExpressions(parameterType.getRegexps());
    messagesParameterType.setPreferForRegularExpressionMatch(parameterType.preferForRegexpMatch());
    messagesParameterType.setUseForSnippets(parameterType.useForSnippets());
    Envelope envelope = new Envelope();
    envelope.setParameterType(messagesParameterType);
    bus.send(envelope);
}
Also used : ParameterType(io.cucumber.cucumberexpressions.ParameterType) Envelope(io.cucumber.messages.types.Envelope)

Example 4 with ParameterType

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

the class JavaParameterTypeDefinition method requireValidMethod.

private static Method requireValidMethod(Method method) {
    Type returnType = method.getGenericReturnType();
    if (Void.class.equals(returnType) || void.class.equals(returnType)) {
        throw createInvalidSignatureException(method);
    }
    Type[] parameterTypes = method.getGenericParameterTypes();
    if (parameterTypes.length == 0) {
        throw createInvalidSignatureException(method);
    }
    if (parameterTypes.length == 1) {
        if (!(String.class.equals(parameterTypes[0]) || String[].class.equals(parameterTypes[0]))) {
            throw createInvalidSignatureException(method);
        }
        return method;
    }
    for (Type parameterType : parameterTypes) {
        if (!String.class.equals(parameterType)) {
            throw createInvalidSignatureException(method);
        }
    }
    return method;
}
Also used : Type(java.lang.reflect.Type) ParameterType(io.cucumber.cucumberexpressions.ParameterType)

Aggregations

ParameterType (io.cucumber.cucumberexpressions.ParameterType)4 Type (java.lang.reflect.Type)2 Expression (io.cucumber.cucumberexpressions.Expression)1 Envelope (io.cucumber.messages.types.Envelope)1 DataTableArgument (io.cucumber.plugin.event.DataTableArgument)1 DocStringArgument (io.cucumber.plugin.event.DocStringArgument)1 StepArgument (io.cucumber.plugin.event.StepArgument)1 LinkedHashMap (java.util.LinkedHashMap)1 Test (org.junit.jupiter.api.Test)1