Placeholders { public static Map<Pattern,String> compile(Map<String,String> placeholders) { Map<Pattern,String> compiled = new HashMap<Pattern, String>(); for (Map.Entry<String, String> entry : placeholders.entrySet()) { String placeholder = entry.getKey(); String value = entry.getValue(); compiled.put(Pattern.compile("\\{" + Pattern.quote(placeholder) + "\\}"), value); } return unmodifiableMap(compiled); } private  Placeholders(); static Map<Pattern,String> compile(Map<String,String> placeholders); static String merge(Map<Pattern,String> placeholders, String str);  }
@Test public void compileShouldReturnACompiledVersionOfGivenPlaceholdeMap(){ Map<String,String> placeholders = Collections.singletonMap("te.st", "someval"); Map<Pattern, String> actual = Placeholders.compile(placeholders); assertNotNull(actual); assertEquals(1, actual.size()); Map.Entry<Pattern,String> entry = actual.entrySet().iterator().next(); assertEquals("someval", entry.getValue()); assertEquals("\\{\\Qte.st\\E\\}", entry.getKey().pattern()); }