TagRegistry { public static String replaceTags(String line, FilterContext filterTask) { Matcher tagMatcher = Pattern.compile("%(\\w+)%", Pattern.CASE_INSENSITIVE).matcher(line); boolean result = tagMatcher.find(); if (!result) return line; StringBuffer sb = new StringBuffer(); do { Tag tag = getTag(tagMatcher.group(1)); if (tag != null) { tagMatcher.appendReplacement(sb, wrapReplacement(tag.getValue(filterTask))); } else { tagMatcher.appendReplacement(sb, tagMatcher.group()); } result = tagMatcher.find(); } while (result); tagMatcher.appendTail(sb); return sb.toString(); }  static String replaceTags(String line, FilterContext filterTask);  }
@Test public void testUntaggedStringIsUnmodified() { FilterContextImpl testState = new FilterContextImpl("TestString", testAuthor, testClient); String input = "This is a test"; String result = TagRegistry.replaceTags(input, testState); Assert.assertEquals(input, result); }
@Test public void testUnmatchedTagIsUnmodified() { FilterContextImpl testState = new FilterContextImpl("TestString", testAuthor, testClient); String input = "This is a %nonexistenttag%"; String result = TagRegistry.replaceTags(input, testState); Assert.assertEquals(input, result); }