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("^(.*)$"));
}
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;
}
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);
}
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;
}
Aggregations