### Question:
PathSpecification { public Map<String, String> parseParams(String path) { Map<String, String> res = new HashMap<>(); String params = path.substring(prefix.length()); if (!params.isEmpty()) { String[] elements = params.split("/"); int start = 0; if (elements.length > 0) { if (elements[0].isEmpty()) { start = 1; } } for (int i = start; i < elements.length; i++) { if (i >= paramNames.size() + start) { break; } res.put(paramNames.get(i - start), elements[i]); } } return res; } PathSpecification(); static PathSpecification fromSpecString(String pathSpec); boolean matches(String path); Map<String, String> parseParams(String path); public String prefix; public List<String> paramNames; public String pathSpec; }### Answer:
@Test public void testParseParams() { String pathSpec = "/test/one/{param1}/{param2}"; PathSpecification ps = PathSpecification.fromSpecString(pathSpec); Map<String,String> params = ps.parseParams("/test/one/1"); assertEquals("1", params.get("param1")); assertEquals(null, params.get("param2")); Map<String,String> params1 = ps.parseParams("/test/one/1/2"); assertEquals("1", params1.get("param1")); assertEquals("2", params1.get("param2")); Map<String,String> params2 = ps.parseParams("test/one/1/2"); assertEquals("1", params1.get("param1")); assertEquals("2", params1.get("param2")); }