### Question:
PropertyUtil { public static Map<String, String> filterProperties(Map<String, String> properties, String optionPrefix) { if (properties == null) { throw new IllegalArgumentException("The given properties object was null."); } Map<String, String> rc = new LinkedHashMap<String, String>(properties.size()); for (Iterator<Entry<String, String>> iter = properties.entrySet().iterator(); iter.hasNext();) { Entry<String, String> entry = iter.next(); if (entry.getKey().startsWith(optionPrefix)) { String name = entry.getKey().substring(optionPrefix.length()); rc.put(name, entry.getValue()); iter.remove(); } } return rc; }  static URI replaceQuery(URI originalURI, Map<String, String> properties); static URI replaceQuery(URI uri, String query); static URI eraseQuery(URI uri); static String createQueryString(Map<String, ? extends Object> options); static Map<String, String> parseQuery(URI uri); static Map<String, String> parseQuery(String queryString); static Map<String, String> filterProperties(Map<String, String> properties, String optionPrefix); static Map<String, String> setProperties(Object target, Map<String, String> properties); static Map<String, Object> setProperties(Object target, Properties properties); static Map<String, String> getProperties(Object object); static Object getProperty(Object object, String name); static boolean setProperty(Object target, String name, Object value); static String stripPrefix(String value, String prefix); static String stripUpto(String value, char c); static String stripBefore(String value, char c);  }### Answer:
@Test(expected=IllegalArgumentException.class) public void testFilterPropertiesNullProperties() throws Exception { PropertyUtil.filterProperties(null, "option."); }
@Test public void testFilterPropertiesNoFilter() throws Exception { Map<String, String> properties = new HashMap<String, String>(); properties.put("unprefixied", "true"); properties.put("option.filtered1", "true"); properties.put("option.filtered2", "false"); Map<String, String> result = PropertyUtil.filterProperties(properties, "option."); assertEquals(2, result.size()); assertTrue(result.containsKey("filtered1")); assertTrue(result.containsKey("filtered2")); assertFalse(result.containsKey("unprefixed")); assertEquals("true", result.get("filtered1")); assertEquals("false", result.get("filtered2")); }