@Test public void unmatched_optional_groups_have_null_values() { ParameterTypeRegistry parameterTypeRegistry = new ParameterTypeRegistry(Locale.ENGLISH); parameterTypeRegistry.defineParameterType(new ParameterType<>( "textAndOrNumber", singletonList("([A-Z]+)?(?: )?([0-9]+)?"), new TypeReference<List<String>>() { }.getType(), new CaptureGroupTransformer<List<String>>() { @Override public List<String> transform(String... args) { return asList(args); } }, false, false) ); assertThat(match("{textAndOrNumber}", "TLA", parameterTypeRegistry), is(singletonList(asList("TLA", null)))); assertThat(match("{textAndOrNumber}", "123", parameterTypeRegistry), is(singletonList(asList(null, "123")))); }
@Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } List<ParameterType<?>> parameterTypes = new ArrayList<>(this.parameterTypes); for (int i = 0; i < parameterTypes.size(); i++) { ParameterType<?> parameterType = parameterTypes.get(i); Type type = i < typeHints.length ? typeHints[i] : String.class; if (parameterType.isAnonymous()) { ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); parameterTypes.set(i, parameterType.deAnonymize(type, arg -> defaultTransformer.transform(arg, type))); } } return Argument.build(group, treeRegexp, parameterTypes); }
CucumberExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } List<ParameterType<?>> parameterTypes = new ArrayList<>(this.parameterTypes); for (int i = 0; i < parameterTypes.size(); i++) { ParameterType<?> parameterType = parameterTypes.get(i); Type type = i < typeHints.length ? typeHints[i] : String.class; if (parameterType.isAnonymous()) { ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); parameterTypes.set(i, parameterType.deAnonymize(type, arg -> defaultTransformer.transform(arg, type))); } } return Argument.build(group, treeRegexp, parameterTypes); } }
CucumberExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } List<ParameterType<?>> parameterTypes = new ArrayList<>(this.parameterTypes); for (int i = 0; i < parameterTypes.size(); i++) { ParameterType<?> parameterType = parameterTypes.get(i); Type type = i < typeHints.length ? typeHints[i] : String.class; if (parameterType.isAnonymous()) { ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); parameterTypes.set(i, parameterType.deAnonymize(type, arg -> defaultTransformer.transform(arg, type))); } } return Argument.build(group, treeRegexp, parameterTypes); } CucumberExpression(String expression, ParameterTypeRegistry parameterTypeRegistry); }
CucumberExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } List<ParameterType<?>> parameterTypes = new ArrayList<>(this.parameterTypes); for (int i = 0; i < parameterTypes.size(); i++) { ParameterType<?> parameterType = parameterTypes.get(i); Type type = i < typeHints.length ? typeHints[i] : String.class; if (parameterType.isAnonymous()) { ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); parameterTypes.set(i, parameterType.deAnonymize(type, arg -> defaultTransformer.transform(arg, type))); } } return Argument.build(group, treeRegexp, parameterTypes); } CucumberExpression(String expression, ParameterTypeRegistry parameterTypeRegistry); @Override List<Argument<?>> match(String text, Type... typeHints); @Override String getSource(); @Override Pattern getRegexp(); }
CucumberExpression implements Expression { @Override public List<Argument<?>> match(String text, Type... typeHints) { final Group group = treeRegexp.match(text); if (group == null) { return null; } List<ParameterType<?>> parameterTypes = new ArrayList<>(this.parameterTypes); for (int i = 0; i < parameterTypes.size(); i++) { ParameterType<?> parameterType = parameterTypes.get(i); Type type = i < typeHints.length ? typeHints[i] : String.class; if (parameterType.isAnonymous()) { ParameterByTypeTransformer defaultTransformer = parameterTypeRegistry.getDefaultParameterTransformer(); parameterTypes.set(i, parameterType.deAnonymize(type, arg -> defaultTransformer.transform(arg, type))); } } return Argument.build(group, treeRegexp, parameterTypes); } CucumberExpression(String expression, ParameterTypeRegistry parameterTypeRegistry); @Override List<Argument<?>> match(String text, Type... typeHints); @Override String getSource(); @Override Pattern getRegexp();  }