### Question:
TokenResolver { public void resolve(Map<String, String> map) { Map<String, String> newEntries = new HashMap<String,String>(); Set<Map.Entry<String,String>> set = map.entrySet(); Iterator<Map.Entry<String,String>> it = set.iterator(); while(it.hasNext()) { Map.Entry<String,String> entry = it.next(); String key = entry.getKey(); String value = entry.getValue(); if (hasToken(value)) { value = resolve(value); map.put(key, value); } if(hasToken(key)) { String newKey = resolve(key); newEntries.put(newKey, value); it.remove(); } } map.putAll(newEntries); } TokenResolver();  TokenResolver(Map<String, String> map); void resolve(Map<String, String> map); void resolve(List<String> list); String resolve(String s); static boolean hasToken(String s);  }### Answer:
@Test public void testResolve_Map() { Map<String,String> map2 = new HashMap<String,String>(); map2.put("foo", "${name1}"); map2.put("foo2", "${name111}"); map2.put("zzz${name3}zzz", "zzz"); map2.put("qqq${name2}qqq", "${name4}"); TokenResolver instance = new TokenResolver(testMap); instance.resolve(map2); assertEquals(map2.get("foo"), "value1"); assertEquals(map2.get("foo2"), "${name111}"); assertNull(map2.get("qqq${name2}qqq")); assertEquals(map2.get("qqqvalue2qqq"), "value4"); assertEquals(map2.get("zzzvalue3zzz"), "zzz"); instance.resolve(map2); }
@Test public void testResolve_String() { TokenResolver instance = new TokenResolver(testMap); String expResult = "xyzvalue1xyz"; String result = instance.resolve("xyz${name1}xyz"); assertEquals(expResult, result); expResult = "xyz$value1xyz"; result = instance.resolve("xyz$${name1}xyz"); assertEquals(expResult, result); expResult = "xyzvalue1}xyz"; result = instance.resolve("xyz${name1}}xyz"); assertEquals(expResult, result); expResult = "xyzvalue4xyz"; result = instance.resolve("xyz${name4}xyz"); assertEquals(expResult, result); expResult = "xyz${name5}xyz"; result = instance.resolve("xyz${name5}xyz"); assertEquals(expResult, result); }
@Test public void testResolve_Map() { Map<String,String> map2 = new HashMap<String,String>(); map2.put("foo", "${name1}"); map2.put("foo2", "${name111}"); map2.put("zzz${name3}zzz", "zzz"); map2.put("qqq${name2}qqq", "${name4}"); TokenResolver instance = new TokenResolver(testMap); instance.resolve(map2); assertEquals("value1", map2.get("foo")); assertEquals("${name111}", map2.get("foo2")); assertNull(map2.get("qqq${name2}qqq")); assertEquals("value4", map2.get("qqqvalue2qqq")); assertEquals("zzz", map2.get("zzzvalue3zzz")); instance.resolve(map2); }