### Question:
PropertyUtil { public static Map<String, String> setProperties(Object target, Map<String, String> properties) { if (target == null) { throw new IllegalArgumentException("target object cannot be null"); } if (properties == null) { throw new IllegalArgumentException("Given Properties object cannot be null"); } Map<String, String> unmatched = new LinkedHashMap<String, String>(); for (Map.Entry<String, String> entry : properties.entrySet()) { if (!setProperty(target, entry.getKey(), entry.getValue())) { unmatched.put(entry.getKey(), entry.getValue()); } } return Collections.unmodifiableMap(unmatched); }  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 public void testSetProperties() throws Exception { Options configObject = new Options(); Map<String, String> properties = new HashMap<String, String>(); properties.put("firstName", "foo"); properties.put("lastName", "bar"); assertTrue(PropertyUtil.setProperties(configObject, properties).isEmpty()); assertEquals("foo", configObject.getFirstName()); assertEquals("bar", configObject.getLastName()); }
@Test(expected = IllegalArgumentException.class) public void testSetPropertiesThrowsOnNullObject() throws Exception { Map<String, String> properties = new HashMap<String, String>(); properties.put("firstName", "foo"); properties.put("lastName", "bar"); PropertyUtil.setProperties(null, properties); }
@Test public void testSetPropertiesUsingPropertiesObject() throws Exception { Options configObject = new Options(); Properties properties = new Properties(); properties.put("firstName", "foo"); properties.put("lastName", "bar"); assertTrue(PropertyUtil.setProperties(configObject, properties).isEmpty()); assertEquals("foo", configObject.getFirstName()); assertEquals("bar", configObject.getLastName()); }
@Test public void testSetPropertiesWithUnusedOptions() throws Exception { Options configObject = new Options(); Map<String, String> properties = new HashMap<String, String>(); properties.put("firstName", "foo"); properties.put("lastName", "bar"); properties.put("unused", "absent"); Map<String, String> result = PropertyUtil.setProperties(configObject, properties); assertFalse(result.isEmpty()); assertTrue(result.containsKey("unused")); assertEquals("foo", configObject.getFirstName()); assertEquals("bar", configObject.getLastName()); }
@Test public void testSetPropertiesWithUnusedOptionsUsingPropertiesObject() throws Exception { Options configObject = new Options(); Properties properties = new Properties(); properties.put("firstName", "foo"); properties.put("lastName", "bar"); properties.put("unused", "absent"); Map<String, Object> result = PropertyUtil.setProperties(configObject, properties); assertFalse(result.isEmpty()); assertTrue(result.containsKey("unused")); assertEquals("foo", configObject.getFirstName()); assertEquals("bar", configObject.getLastName()); }
@Test(expected=IllegalArgumentException.class) public void testSetPropertiesWithNullObject() { PropertyUtil.setProperties(null, new HashMap<String, String>()); }
@Test(expected=IllegalArgumentException.class) public void testSetPropertiesWithNullMap() { PropertyUtil.setProperties(new Options(), (Map<String, String>) null); }
@Test(expected=IllegalArgumentException.class) public void testSetPropertiesWithNullProperties() { PropertyUtil.setProperties(new Options(), (Properties) null); }