@Test public void testInterpolateNonexistent() { boolean interpolatedNonexistentProperty = false; try { InterpolationProperties props = new InterpolationProperties(new Properties()); props.interpolate("123 ${does.not.exist} 456"); interpolatedNonexistentProperty = true; } catch (Exception e) { } assertFalse(interpolatedNonexistentProperty); }
public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } InterpolationProperties(Properties theProperties);  InterpolationProperties(String identifier);  InterpolationProperties(); }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } InterpolationProperties(Properties theProperties);  InterpolationProperties(String identifier);  InterpolationProperties(); void setProperty(String propName, String value); String getProperty(String propName); String interpolate(String input); static String readAll(InputStream input); }
InterpolationProperties { public String interpolate(String input) { String result = input; Matcher matcher = PROPERTY_INTERPOLATION_PATTERN.matcher(result); while (matcher.find()) { String propertyName = matcher.group(1); String propertyValue = (String) theProperties.get(propertyName); if (propertyValue == null) { throw new RuntimeException("Interpolation failed for missing property " + propertyName); } else { result = result.replace(matcher.group(), propertyValue).trim(); matcher.reset(result); } } return result; } InterpolationProperties(Properties theProperties);  InterpolationProperties(String identifier);  InterpolationProperties(); void setProperty(String propName, String value); String getProperty(String propName); String interpolate(String input); static String readAll(InputStream input);  }