### Question:
PathSpecification { public static PathSpecification fromSpecString(String pathSpec) { PathSpecification res = new PathSpecification(); res.pathSpec = pathSpec; String[] elements = pathSpec.split("/"); int bracePos = pathSpec.indexOf("{"); if (bracePos > 0) { res.prefix = pathSpec.substring(0, bracePos - 1); for (String element : elements) { if (element.startsWith("{")) { if (element.endsWith("}")) { res.paramNames.add(element.substring(1, element.length() - 1)); } else { log.error("Missing brace in path element {} of path sepce: {}", element, pathSpec); res.paramNames.add(element.substring(1, element.length())); } } } } else { res.prefix = pathSpec; } 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 testFromSpecString() { String pathSpec1 = "/test/one/{param1}/{param2}"; PathSpecification result1 = PathSpecification.fromSpecString(pathSpec1); assertEquals("/test/one", result1.prefix); assertEquals("param1", result1.paramNames.get(0)); assertEquals("param2", result1.paramNames.get(1)); String pathSpec2 = "/test/two/one"; PathSpecification result2 = PathSpecification.fromSpecString(pathSpec2); assertEquals("/test/two/one", result2.prefix); assertEquals(0, result2.paramNames.size()); String pathSpec3 = "/test/one/{param1/{param2}"; PathSpecification result3 = PathSpecification.fromSpecString(pathSpec3); assertEquals("/test/one", result3.prefix); assertEquals("param1", result3.paramNames.get(0)); assertEquals("param2", result3.paramNames.get(1)); }