Config implements Map<String, String>, Serializable { public List<String> getList(String k, List<String> defaultValue) { if (!containsKey(k)) return defaultValue; String value = get(k); if (value.trim().isEmpty()) { return defaultValue; } String[] pieces = value.split("\\s*,\\s*"); return Arrays.asList(pieces); }  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 testGetList() { Map<String, String> m = new HashMap<String, String>() { { put("key1", " "); put("key2", ""); put("key3", " value1 "); put("key4", "value1,value2"); put("key5", "value1, value2"); put("key6", "value1 , value2"); } }; Config config = new MapConfig(m); List<String> list = config.getList("key1", Collections.<String>emptyList()); assertEquals(0, list.size()); list = config.getList("key2", Collections.<String>emptyList()); assertEquals(0, list.size()); list = config.getList("key3"); assertEquals(" value1 ", list.get(0)); list = config.getList("key4"); assertEquals("value1", list.get(0)); assertEquals("value2", list.get(1)); list = config.getList("key5"); assertEquals("value1", list.get(0)); assertEquals("value2", list.get(1)); list = config.getList("key6"); assertEquals("value1", list.get(0)); assertEquals("value2", list.get(1)); list = config.getList("UndefinedKey", Collections.<String>emptyList()); assertEquals(0, list.size()); }