UriPatten implements Comparable<UriPatten> { public Optional<Map<String, String>> match(String uri) { Matcher matcher = this.pattern.matcher(uri); if (matcher.matches()) { if (!variableNames.isEmpty()) { Map<String, String> result = new HashMap<>(variableNames.size()); for (int i = 0; i < variableNames.size(); i++) { String name = variableNames.get(i); String value = matcher.group(i + 1); result.put(name, value); } return Optional.of(result); } return Optional.of(Collections.emptyMap()); } else { return Optional.empty(); } } UriPatten(String uriPattern); boolean matches(String uri); Optional<Map<String, String>> match(String uri); @Override int hashCode(); @Override int compareTo(UriPatten otherUriPattern); @Override boolean equals(Object obj); @Override String toString();  }
@Test(dataProvider = "matchingUriPatterns") public void testPatternsWithParameters(String uriPattern, String uri) { Assert.assertTrue(new UriPatten(uriPattern).match(uri).isPresent()); }
@Test(dataProvider = "unmatchingUriPatterns") public void testUnMatchingPatternsWithParameters(String uriPattern, String uri) { Assert.assertFalse(new UriPatten(uriPattern).match(uri).isPresent()); }