### Question:
LogbackPatternLayout extends PatternLayout { String modifyMessage(String message) { String logMessage = message; for (Map.Entry<Pattern, String> next : mapForReplacement.entrySet()) { logMessage = next.getKey().matcher(logMessage).replaceAll(next.getValue()); } return logMessage; } LogbackPatternLayout(); @Override String doLayout(ILoggingEvent event);  }### Answer:
@Test void testFieldsAndObjectsMask() throws IOException { Map<String, Object> testMap = new HashMap<>(); testMap.put("password", "password"); testMap.put("encryptedPassword", "encryptedPassword"); testMap.put("additionalPassword", "additionalPassword"); testMap.put("additionalEncryptedPassword", "additionalEncryptedPassword"); testMap.put("access_token", "access_token"); testMap.put("refresh_token", "refresh_token"); testMap.put("ownerName", "ownerName"); Xs2aAddress address = new Xs2aAddress(); address.setTownName("town"); testMap.put("ownerAddress", address); String testMapRepresentation = mapper.writeValueAsString(testMap); String testMapRepresentationModified = layout.modifyMessage(testMapRepresentation); Map<String, Object> map = mapper.readValue(testMapRepresentationModified, new TypeReference<HashMap<String, Object>>() { }); map.forEach((key, value) -> assertEquals(mask, value)); }
@Test void testAuthorizationHeaderMask() { String authorization = "authorization: "; String bearer = "Bearer 1234567"; String headerModified = layout.modifyMessage(authorization + bearer); assertEquals(authorization + mask, headerModified); }
@Test void testFieldsAndObjectsNoMask() throws IOException { Map<String, Object> testMap = new HashMap<>(); AccountReference accountReference = new AccountReference(); accountReference.setIban("IBAN"); List<AccountReference> accountReferenceList = Collections.singletonList(accountReference); testMap.put("ownerName", accountReferenceList); testMap.put("ownerAddress", accountReferenceList); String testMapRepresentation = mapper.writeValueAsString(testMap); String testMapRepresentationModified = layout.modifyMessage(testMapRepresentation); Map<String, Object> map = mapper.readValue(testMapRepresentationModified, new TypeReference<HashMap<String, Object>>() { }); map.forEach((key, value) -> assertNotSame(mask, value)); }