### Question:
PropertiesResolver { public static Properties resolveProperties(Properties properties, Properties resolvedProperties) { if (properties == null) { return null; } return resolveProperties(copyProperties(properties), copyProperties(resolvedProperties), new HashSet<String>(5)); } private  PropertiesResolver(); static Properties resolveProperties(Properties properties, Properties resolvedProperties); static Properties resolveProperties(Properties properties);  }### Answer:
@Test public void testResolvePropertiesPropertiesProperties() { Properties p1 = new Properties(); p1.setProperty("key1", "value1"); p1.setProperty("key2", "value2"); p1.setProperty("key7", "${key1}"); Map<Object, Object> p1Copy = new HashMap<Object, Object>(p1); Properties p2 = new Properties(); p2.setProperty("key3", "${key1}"); p2.setProperty("key4", "${key2}"); Map<Object, Object> p2Copy = new HashMap<Object, Object>(p2); Properties p3 = PropertiesResolver.resolveProperties(p2, p1); assertEquals(p1Copy, p1); assertEquals(p2Copy, p2); assertEquals("value1", p3.getProperty("key3")); assertEquals("value2", p3.getProperty("key4")); }
@Test public void testSimpleResolveProperties() throws InterruptedException { Properties properties = new Properties(); properties.setProperty("key1", "value1"); properties.setProperty("key2", "Value of key1 is ${key1}"); properties.setProperty("key3", "Reference ${key4}"); properties = PropertiesResolver.resolveProperties(properties); Assert.assertEquals("Value of key1 is value1", properties.get("key2")); Assert.assertEquals("Reference ${key4}", properties.get("key3")); }
@Test public void testAdvancedResolved() { Properties properties = new Properties(); properties.setProperty("key1", "value1"); properties.setProperty("key2", "${key1}"); properties.setProperty("key3", "value3"); properties.setProperty("key4", "${key2} ${key3}"); properties = PropertiesResolver.resolveProperties(properties); Assert.assertEquals("value1 value3", properties.get("key4")); }
@Test public void testRecursion() { Properties properties = new Properties(); properties.setProperty("key1", "value1 ${key3}"); properties.setProperty("key2", "value2 ${key1}"); properties.setProperty("key3", "value3 ${key2}"); properties = PropertiesResolver.resolveProperties(properties); System.out.println(properties.get("key3")); Assert.assertEquals("value3 value2 value1 RECURSION", properties.get("key3")); }