### Question:
BatchOperations { protected String replaceLocationPlaceholders( String str, Map<Integer, String> locations ) { if ( !str.contains( "{" ) ) { return str; } Matcher matcher = PLACEHOLDER_PATTERN.matcher( str ); StringBuffer sb = new StringBuffer(); String replacement = null; while ( matcher.find() ) { String id = matcher.group( 1 ); try { replacement = locations.get( Integer.valueOf( id ) ); } catch ( NumberFormatException e ) { } if ( replacement != null ) { matcher.appendReplacement( sb, replacement ); } else { matcher.appendReplacement( sb, matcher.group() ); } } matcher.appendTail( sb ); return sb.toString(); } BatchOperations( WebServer webServer );   }### Answer:
@Test public void testReplaceLocations() { Map<Integer,String> map = new HashMap<>(); map.put(100,"bar"); assertEquals("foo", ops.replaceLocationPlaceholders("foo", map)); assertEquals("foo bar", ops.replaceLocationPlaceholders("foo {100}", map)); assertEquals("bar foo bar", ops.replaceLocationPlaceholders("{100} foo {100}", map)); assertEquals("bar bar foo bar bar", ops.replaceLocationPlaceholders("bar {100} foo {100} bar", map)); }
@Test public void shouldIgnoreUnknownAndUnparseablePlaceholders() { assertEquals("foo {00000000010001010001001100111000100101010111001101110111}", ops.replaceLocationPlaceholders("foo {00000000010001010001001100111000100101010111001101110111}", Collections.emptyMap() )); assertEquals("foo {2147483648}", ops.replaceLocationPlaceholders("foo {2147483648}", Collections.emptyMap() )); }