JavaParamFilter extends RecipeFilter { @Override public Object apply(Object value, Object... params) { Map<String, Object> param = (Map<String, Object>) value; String name = (String) param.get("name"); boolean varargAsArray = params.length > 0 && super.asBoolean(params[0]); return typeFilter.apply(param.get("type"), varargAsArray) + " " + identifierFilter.apply(name); } JavaParamFilter(Cookbook cookbook, Filter typeFilter, Filter identifierFilter); @Override Object apply(Object value, Object... params);  }
@Test public void testApply_combinesTypeAndNameFromFilters() { Cookbook cookbook = new Cookbook("test", new ArrayList<>(), new ArrayList<>()); Filter filter = new JavaParamFilter(cookbook, javaTypeFilter, javaIdentifierFilter); Map param = new HashMap(); param.put("name", "foo"); param.put("type", "int[]"); when(javaTypeFilter.apply(param.get("type"), false)).thenReturn("type"); when(javaIdentifierFilter.apply(param.get("name"))).thenReturn("identifier"); assertEquals("type identifier", filter.apply(param)); }
@Test public void testApply_passesCollapseVarargOptionToTypeFilter() { Cookbook cookbook = new Cookbook("test", new ArrayList<>(), new ArrayList<>()); Filter filter = new JavaParamFilter(cookbook, javaTypeFilter, javaIdentifierFilter); Map param = new HashMap(); param.put("name", "foo"); param.put("type", "int[]"); filter.apply(param, true); verify(javaTypeFilter).apply(param.get("type"), true); }