### Question:
ParameterList { public String replace(String string, boolean strict) { if (string == null) { throw new IllegalArgumentException("string must not be null"); } StringBuilder buf = new StringBuilder(); int start = 0; Matcher matcher = VARIABLE.matcher(string); while (matcher.find(start)) { String name = matcher.group(1); String replacement = resolve(name); if (replacement == null) { if (strict) { WGLOG.error("E99001", name); throw new IllegalArgumentException(MessageFormat.format( "parameter \"{0}\" is not defined in the list: {1}", name, this)); } else { buf.append(string.substring(start, matcher.start() + 1)); } start = matcher.start() + 1; } else { buf.append(string.substring(start, matcher.start())); buf.append(replacement); start = matcher.end(); } } buf.append(string.substring(start)); return buf.toString(); } ParameterList();  ParameterList(Map<String, String> parameters); Map<String, String> getPairs(); String replace(String string, boolean strict); @Override String toString();  }### Answer:
@Test public void inLine() { Map<String, String> map = new HashMap<>(); map.put("message", "Hello, world!"); ParameterList resolver = new ParameterList(map); assertThat(resolver.replace(">>> ${message} <<<", true), is(">>> Hello, world! <<<")); }
@Test public void multiple() { Map<String, String> map = new HashMap<>(); map.put("m1", "Hello1"); map.put("m2", "Hello2"); map.put("m3", "Hello3"); ParameterList resolver = new ParameterList(map); assertThat(resolver.replace("${m1}, ${m2}, ${m3}!", true), is("Hello1, Hello2, Hello3!")); }
@Test public void with_default_present() { Map<String, String> map = new HashMap<>(); map.put("message", "Hello, world!"); ParameterList resolver = new ParameterList(map); assertThat(resolver.replace("${message-MISSING}", true), is("Hello, world!")); }
@Test public void with_default_missing() { Map<String, String> map = new HashMap<>(); ParameterList resolver = new ParameterList(map); assertThat(resolver.replace("${message-MISSING}", true), is("MISSING")); }
@Test(expected = IllegalArgumentException.class) public void invalid_strict() { Map<String, String> map = new HashMap<>(); ParameterList resolver = new ParameterList(map); resolver.replace("${MISSING}", true); }
@Test public void invalid_keep() { Map<String, String> map = new HashMap<>(); ParameterList resolver = new ParameterList(map); assertThat(resolver.replace("${MISSING}", false), is("${MISSING}")); }