### Question:
Event { public String escapeString(String in) { Matcher matcher = tagPattern.matcher(in); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String replacement = ""; if (matcher.group(2) != null) { replacement = mapTagToString(matcher.group(2)); if (replacement == null) { replacement = ""; LOG.warn("Tag " + matcher.group(2) + " not found"); } } else { Preconditions.checkState(matcher.group(1) != null && matcher.group(1).length() == 1, "Expected to match single character tag in string " + in); replacement = replaceShorthand(matcher.group(1).charAt(0)); } matcher.appendReplacement(sb, replacement); } matcher.appendTail(sb); return sb.toString(); }  abstract byte[] getBody(); abstract Priority getPriority(); abstract long getTimestamp(); abstract long getNanos(); abstract String getHost(); abstract byte[] get(String attr); abstract void set(String attr, byte[] v); abstract Map<String, byte[]> getAttrs(); abstract void merge(Event e); abstract void hierarchicalMerge(String prefix, Event e); static boolean containsTag(String in); String escapeString(String in); Map<String, String> getEscapeMapping(String in); final static String A_SERVICE; final static String TAG_REGEX; final static Pattern tagPattern; }### Answer:
@Test public void testSpecialEscaping() { Event e = new EventImpl("abcde".getBytes()); String test = "/henry/%{body}-test"; test = e.escapeString(test); assertEquals("Tag replacement of host failed!", "/henry/abcde-test", test); test = e.escapeString("/henry/%f"); assertEquals("Tag replacement of unknown single character tag failed!", "/henry/", test); }
@Test public void testMatchOrdering() { String test = "%%{henry}"; Event e = new EventImpl("abcde".getBytes()); test = e.escapeString(test); assertEquals("Replacement of tags in order failed: " + test, "%{henry}", test); }
@Test public void testDateFormat() { String test = "%a"; Event e = new EventImpl(new byte[0], 1267578391, Priority.INFO, 0, "localhost"); test = e.escapeString(test); assertEquals("Replacement of tag by date failed: " + test, "Thu", test); }