ContextInflater extends BaseContextHandler { String inflateGroups(String input, Set<String> groups) { String result = input; for (String key : groups) { Optional<String> $value = world.get(key); if ($value.isPresent()) { result = result.replaceAll("\\{\\(" + key + "\\)}", $value.get()); } } return result; }  String inflate(String input);  }
@Test public void testInflateGroups() { doReturn(Optional.of("foo")).when(world).get("foo"); String value = inflater.inflateGroups("{(foo)} bar", Sets.newHashSet("foo")); assertThat(value, equalTo("foo bar")); }
@Test public void testInflateGroups_emptyWorld() { String value = inflater.inflateGroups("{(foo)} bar", Sets.newHashSet("foo")); assertThat(value, equalTo("{(foo)} bar")); }
@Test public void testInflateGroups_multipleEmpty() { String value = inflater.inflateGroups("{(foo)} {(bar)}", Sets.newHashSet("foo", "bar")); assertThat(value, equalTo("{(foo)} {(bar)}")); }
@Test public void testInflateGroups_halfEmpty() { doReturn(Optional.of("foo")).when(world).get("foo"); String value = inflater.inflateGroups("{(foo)} {(bar)}", Sets.newHashSet("foo", "bar")); assertThat(value, equalTo("foo {(bar)}")); }
@Test public void testInflateGroups_withPlainText() { doReturn(Optional.of("foo")).when(world).get("foo"); String value = inflater.inflateGroups("my {(foo)} is very {(bar)} !", Sets.newHashSet("foo", "bar")); assertThat(value, equalTo("my foo is very {(bar)} !")); }
@Test public void testInflateGroups_multipleExist() { doReturn(Optional.of("foo")).when(world).get("foo"); doReturn(Optional.of("bar")).when(world).get("bar"); String value = inflater.inflateGroups("{(foo)} {(bar)}", Sets.newHashSet("foo", "bar")); assertThat(value, equalTo("foo bar")); }
@Test public void testInflateGroups_multipleSameExist() { doReturn(Optional.of("foo")).when(world).get("foo"); String value = inflater.inflateGroups("{(foo)} {(foo)}", Sets.newHashSet("foo")); assertThat(value, equalTo("foo foo")); }
@Test public void testInflateGroups_multipleSameEmpty() { String value = inflater.inflateGroups("{(foo)} {(foo)}", Sets.newHashSet("foo")); assertThat(value, equalTo("{(foo)} {(foo)}")); }