### Question:
DefinedRegexMaskingConverter extends ClassicConverter { @Override public String convert(ILoggingEvent logEvent) { String message = logEvent.getMessage(); Set<Pattern> patternSet = patternMap.keySet(); if (message!=null && !message.equals("")) { for (Pattern pattern : patternSet) { message = pattern.matcher(message).replaceAll(patternMap.get(pattern)); } } return message; }  @Override String convert(ILoggingEvent logEvent); @Override void start();  }### Answer:
@Test public void testCompleteMask(){ String masked = mc.convert(getEvent("")); assertEquals("", masked); masked = mc.convert(getEvent("password=abc123")); assertEquals("password=*****", masked); masked = mc.convert(getEvent("password:abc123")); assertEquals("password:*****", masked); masked = mc.convert(getEvent("\"password\":\"abc123\"")); assertEquals("\"password\":\"*****\"", masked); masked = mc.convert(getEvent("\"password\":\"abc123\",signature=foo")); assertEquals("\"password\":\"*****\",signature=*****", masked); }
@Test public void testLast4Mask(){ String masked = mc.convert(getEvent("username=abc123")); assertEquals("username=ab*****", masked); masked = mc.convert(getEvent("username:abc123")); assertEquals("username:ab*****", masked); masked = mc.convert(getEvent("\"username\":\"abc123\"")); assertEquals("\"username\":\"ab*****\"", masked); masked = mc.convert(getEvent("\"username\":\"abc123\",signature=foo")); assertEquals("\"username\":\"ab*****\",signature=*****", masked); }
@Test public void testFirst4Mask(){ String masked = mc.convert(getEvent("orderNumber=77887765567abc123")); assertEquals("orderNumber=*****c123", masked); masked = mc.convert(getEvent("orderNumber:abc123")); assertEquals("orderNumber:*****c123", masked); masked = mc.convert(getEvent("\"orderNumber\":\"abc123\"")); assertEquals("\"orderNumber\":\"*****c123\"", masked); masked = mc.convert(getEvent("\"orderNumber\":\"abc123\",signature=foo")); assertEquals("\"orderNumber\":\"*****c123\",signature=*****", masked); }
@Test public void testEmail(){ String masked = mc.convert(getEvent("email=foo@bar.com")); assertEquals("email=foo*****", masked); masked = mc.convert(getEvent("email:foo@bar.com.sg")); assertEquals("email:foo*****", masked); masked = mc.convert(getEvent("\"email\":\"foo.baz@bar.com\"")); assertEquals("\"email\":\"foo.baz*****\"", masked); masked = mc.convert(getEvent("\"email\":\"foo@bar.com.sg\",signature=foo")); assertEquals("\"email\":\"foo*****\",signature=*****", masked); }