PathTemplateFilter { public static PathTemplateFilter parse(List<String> attributes) throws ParseException { if (attributes == null || attributes.isEmpty()) { return NO_OP_FILTER; } Builder builder = null; for (String attribute : attributes) { for (String attr : PathAddress.split(attribute, ";")) { Matcher matcher = PATH_TEMPLATE_PATTERN.matcher(attr); if (matcher.matches()) { String pathTemplate = matcher.group(1); if (builder == null) { builder = create(pathTemplate); } else { builder.and(pathTemplate); } boolean exclusion = (matcher.group(2) != null); List<String> expressions = PathAddress.split(matcher.group(3), ","); for (String expression : expressions) { boolean wildcard = WILDCARD.equals(expression); if (exclusion) { if (wildcard) { builder.excludeAll(); } else { builder.exclude(expression); } } else { if (wildcard) { builder.includeAll(); } else { builder.include(expression); } } } } else { throw new ParseException("Filter attribute '" + attribute + "' is not valid.", 0); } } } return (builder == null) ? NO_OP_FILTER : builder.build(); }  abstract boolean hasPathTemplate(String pathTemplateName); static PathTemplateFilter parse(List<String> attributes); static Builder create(String pathTemplate);  }
@Test public void testAllowNullsOnParse() throws ParseException { PathTemplateFilter filter = PathTemplateFilter.parse(null); Assert.assertNotNull(filter); Assert.assertTrue(PathAddress.pathAddress("some", "path").accepts(filter)); }
@Test public void testAllowEmptyListOnParse() throws ParseException { PathTemplateFilter filter = PathTemplateFilter.parse(Collections.<String>emptyList()); Assert.assertTrue(PathAddress.pathAddress("some", "path").accepts(filter)); }
@Test(expected = ParseException.class) public void testNoPathTemplateOnParse() throws ParseException { PathTemplateFilter.parse(Collections.singletonList("no-path-template")); }
@Test(expected = ParseException.class) public void testMultipleExclusions() throws ParseException { PathTemplateFilter.parse(Collections.singletonList("template:!first,!second")); }