### Question:
Filtering { public static String filter(String input, Map<String, String> variables) { if (variables.isEmpty()) { return input; } if (input == null || input.isEmpty()) { return input; } String current = input; String last = input; while (current.contains("${") && current.contains("}")) { for (Map.Entry<String, String> entry : variables.entrySet()) { current = current.replace("${" + entry.getKey() + "}", entry.getValue()); } if (last.equals(current)) { return current; } last = current; } return current; } private  Filtering(); static String filter(String input, Map<String, String> variables);  }### Answer:
@Test public void testFilteringWithoutVariables() { String out = Filtering.filter("hello", Collections.emptyMap()); assertThat(out).isEqualTo("hello"); }
@Test public void testFilteringWithoutPlaceholders() { String out = Filtering.filter("hello", new FluentMap<>().add("key", "value")); assertThat(out).isEqualTo("hello"); }
@Test public void testFilteringWithNonMatchingVariables() { String out = Filtering.filter("hello ${nope}", new FluentMap<>().add("key", "value")); assertThat(out).isEqualTo("hello ${nope}"); }
@Test public void testFilteringWithReplacement() { String out = Filtering.filter("hello ${world}", new FluentMap<>().add("world", "vert.x")); assertThat(out).isEqualTo("hello vert.x"); }
@Test public void testFilteringWithPartialReplacement() { String out = Filtering.filter("hello ${world} ${period}", new FluentMap<>().add("world", "vert.x")); assertThat(out).isEqualTo("hello vert.x ${period}"); }
@Test public void testFilteringWithNestedReplacement() { String out = Filtering.filter("hello ${world} ${period}", new FluentMap<>() .add("name", "vert.x") .add("world", "${name}")); assertThat(out).isEqualTo("hello vert.x ${period}"); }
@Test public void testFilteringWithUnfinishedVariables() { String out = Filtering.filter("hello ${world} ${per ", new FluentMap<>() .add("name", "vert.x") .add("world", "${name}")); assertThat(out).isEqualTo("hello vert.x ${per "); }