### Question:
PropertyUtil { public static Map<String, String> getProperties(Object object) throws Exception { if (object == null) { return Collections.emptyMap(); } Map<String, String> properties = new LinkedHashMap<String, String>(); BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); Object[] NULL_ARG = {}; PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); if (propertyDescriptors != null) { for (int i = 0; i < propertyDescriptors.length; i++) { PropertyDescriptor pd = propertyDescriptors[i]; if (pd.getReadMethod() != null && !pd.getName().equals("class") && !pd.getName().equals("properties") && !pd.getName().equals("reference")) { Object value = pd.getReadMethod().invoke(object, NULL_ARG); if (value != null) { if (value instanceof Boolean || value instanceof Number || value instanceof String || value instanceof URI || value instanceof URL) { properties.put(pd.getName(), ("" + value)); } else if (value instanceof SSLContext) { } else { Map<String, String> inner = getProperties(value); for (Map.Entry<String, String> entry : inner.entrySet()) { properties.put(pd.getName() + "." + entry.getKey(), entry.getValue()); } } } } } } return properties; }  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 testGetProperties() throws Exception { Options configObject = new Options("foo", "bar"); Map<String, String> properties = PropertyUtil.getProperties(configObject); assertFalse(properties.isEmpty()); assertEquals("foo", properties.get("firstName")); assertEquals("bar", properties.get("lastName")); }
@Test public void testGetPropertiesHandlesURIs() throws Exception { Options configObject = new Options("foo", "bar"); configObject.setURIValue(new URI("test: Map<String, String> properties = PropertyUtil.getProperties(configObject); assertFalse(properties.isEmpty()); assertEquals("foo", properties.get("firstName")); assertEquals("bar", properties.get("lastName")); assertEquals("test: }
@Test public void testGetPropertiesHandlesURLs() throws Exception { Options configObject = new Options("foo", "bar"); configObject.setURLValue(new URL("http: Map<String, String> properties = PropertyUtil.getProperties(configObject); assertFalse(properties.isEmpty()); assertEquals("foo", properties.get("firstName")); assertEquals("bar", properties.get("lastName")); assertEquals("http: }
@Test public void testGetPropertiesIgnoresSSLContext() throws Exception { Options configObject = new Options("foo", "bar"); configObject.setSSLContext(SSLContext.getDefault()); Map<String, String> properties = PropertyUtil.getProperties(configObject); assertFalse(properties.isEmpty()); assertEquals("foo", properties.get("firstName")); assertEquals("bar", properties.get("lastName")); assertFalse(properties.containsKey("sslContext")); }