Config implements Map<String, String>, Serializable { public abstract Config sanitize();  Config subset(String prefix); Config subset(String prefix, boolean stripPrefix); Config regexSubset(String regex); String get(String k, String defaultString); boolean getBoolean(String k, boolean defaultValue); boolean getBoolean(String k); short getShort(String k, short defaultValue); short getShort(String k); long getLong(String k, long defaultValue); long getLong(String k); int getInt(String k, int defaultValue); int getInt(String k); double getDouble(String k, double defaultValue); double getDouble(String k); List<String> getList(String k, List<String> defaultValue); List<String> getList(String k); @SuppressWarnings("unchecked") Class<T> getClass(String k); @SuppressWarnings("unchecked") T getNewInstance(String k); Date getDate(String k); Date getDate(String k, String format); Date getDate(String k, SimpleDateFormat format); Date getDate(String k, Date defaultValue); Date getDate(String k, String format, Date defaultValue); Date getDate(String k, SimpleDateFormat format, Date defaultValue); abstract Config sanitize(); void clear(); String put(String key, String value); void putAll(Map<? extends String, ? extends String> m); String remove(Object s); void replaceAll(BiFunction<? super String, ? super String, ? extends String> function); static final String SENSITIVE_PREFIX; static final String SENSITIVE_MASK; }
@Test public void testSanitize() { Map<String, String> m = new HashMap<String, String>() { { put("key1", "value1"); put("key2", "value2"); put("sensitive.key3", "secret1"); put("sensitive.key4", "secret2"); } }; Config config = new MapConfig(m); assertFalse(config.toString().contains("secret")); Config sanitized = config.sanitize(); assertEquals("value1", sanitized.get("key1")); assertEquals("value2", sanitized.get("key2")); assertEquals(Config.SENSITIVE_MASK, sanitized.get("sensitive.key3")); assertEquals(Config.SENSITIVE_MASK, sanitized.get("sensitive.key4")); }