### Question:
PathPredicate implements Predicate { @Override public boolean resolve(HttpServerExchange exchange) { Matcher m = this.template.matcher(exchange.getRelativePath()); if (m.matches()) { int count = m.groupCount(); if (count <= names.size()) { Map<String, String> newone = new HashMap<>(); for (int i = 0; i < count; i++) { newone.put(names.get(i), m.group(i + 1)); } exchange.putAttachment(PARAMS, newone); } return true; } return false; } PathPredicate(Pattern template);  PathPredicate(String template); @Override boolean resolve(HttpServerExchange exchange); static final AttachmentKey<Map<String, String>> PARAMS; }### Answer:
@Test public void matchWithMultiVars() throws Exception { setUpRequest("/foo/aaa/baz/ccc"); PathPredicate target = new PathPredicate("/foo/:bar/baz/:foo"); assertTrue(target.resolve(this.exchange)); Map<String, String> m = this.exchange .getAttachment(PathPredicate.PARAMS); assertEquals("aaa", m.get("bar")); assertEquals("ccc", m.get("foo")); }
@Test public void matchWithMultiVarsByRegex() throws Exception { setUpRequest("/foo/aaa/baz/ccc"); PathPredicate target = new PathPredicate( Pattern.compile("/foo/(?<bar>\\w+)/baz/(?<foo>\\w+)")); assertTrue(target.resolve(this.exchange)); Map<String, String> m = this.exchange .getAttachment(PathPredicate.PARAMS); assertEquals("aaa", m.get("bar")); assertEquals("ccc", m.get("foo")); }
@Test public void matchCompletely() throws Exception { setUpRequest("/foo/bar"); PathPredicate target = new PathPredicate("/foo/bar"); assertTrue(target.resolve(this.exchange)); }
@Test public void matchPartial() throws Exception { setUpRequest("/foo/bar/baz"); PathPredicate target = new PathPredicate("/foo/bar"); assertTrue(target.resolve(this.exchange)); }
@Test public void unmatchPartial() throws Exception { setUpRequest("/foo/baz/bar"); PathPredicate target = new PathPredicate("/foo/bar"); assertFalse(target.resolve(this.exchange)); }
@Test public void matchWithOneVars() throws Exception { setUpRequest("/foo/aaa"); PathPredicate target = new PathPredicate("/foo/:bar"); assertTrue(target.resolve(this.exchange)); Map<String, String> m = this.exchange .getAttachment(PathPredicate.PARAMS); assertEquals("aaa", m.get("bar")); }
@Test public void matchWithDots() throws Exception { setUpRequest("/foo/aaa.json"); PathPredicate target = new PathPredicate("/foo/:bar.:ext"); assertTrue(target.resolve(this.exchange)); Map<String, String> m = this.exchange .getAttachment(PathPredicate.PARAMS); assertEquals("aaa", m.get("bar")); assertEquals("json", m.get("ext")); }