### Question:
RegexUtil { public static String encodeEmail(String str) { Matcher mailtoMatch = MAILTO_PATTERN.matcher(str); while (mailtoMatch.find()) { String email = mailtoMatch.group(1); String hexed = encode(email); str = str.replaceFirst("mailto:"+email, "mailto:"+hexed); } return obfuscateEmail(str); }  static String encodeEmail(String str); static String obfuscateEmail(String str); static List<String> getMatches(Pattern pattern, String match, int group); static String encode(String email); static final Pattern MAILTO_PATTERN; static final Pattern EMAIL_PATTERN; }### Answer:
@Test public void testEncodingEmail() { String test = "test <a href='mailto:this@email.com'>email</a> string"; String expect = "test <a href='mailto:%74%68%69%73%40%65%6d%61%69%6c%2e%63%6f%6d'>email</a> string"; String result = RegexUtil.encodeEmail(test) ; assertEquals(expect, result); }
@Test public void testHexEmail() { String test = "test <a href='mailto:this@email.com'>this@email.com</a> string, and this@email.com"; String expect = "test <a href='mailto:%74%68%69%73%40%65%6d%61%69%6c%2e%63%6f%6d'>this-AT-email-DOT-com</a> string, and this-AT-email-DOT-com"; String result = RegexUtil.encodeEmail(test); assertEquals(expect, result); }