@Test public void testValueResolvingMissingReferenceFails() { Config config = Config.builder( ConfigSources.create( Map.of( "wrong", "${missing}" ))) .addFilter(ConfigFilters.valueResolving() .failOnMissingReference(true) .build()) .disableEnvironmentVariablesSource() .disableSystemPropertiesSource() .disableFilterServices() .build(); ConfigException ex = assertThrows(ConfigException.class, () -> { config.get("wrong").asString().get(); }); assertThat(ex.getMessage(), startsWith(String.format(ValueResolvingFilter.MISSING_REFERENCE_ERROR, "wrong"))); assertThat(ex.getCause(), instanceOf(MissingValueException.class)); }
private String format(String template) { Matcher m = PATTERN_REFERENCE.matcher(template); final StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, Matcher.quoteReplacement(root.get(m.group(1)).asString().get())); } m.appendTail(sb); m = PATTERN_BACKSLASH.matcher(sb.toString()); return m.replaceAll(""); }
ValueResolvingFilter implements ConfigFilter { private String format(String template) { Matcher m = PATTERN_REFERENCE.matcher(template); final StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, Matcher.quoteReplacement(root.get(m.group(1)).asString().get())); } m.appendTail(sb); m = PATTERN_BACKSLASH.matcher(sb.toString()); return m.replaceAll(""); } }
ValueResolvingFilter implements ConfigFilter { private String format(String template) { Matcher m = PATTERN_REFERENCE.matcher(template); final StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, Matcher.quoteReplacement(root.get(m.group(1)).asString().get())); } m.appendTail(sb); m = PATTERN_BACKSLASH.matcher(sb.toString()); return m.replaceAll(""); } ValueResolvingFilter(boolean failOnMissingReference);  ValueResolvingFilter(); }
ValueResolvingFilter implements ConfigFilter { private String format(String template) { Matcher m = PATTERN_REFERENCE.matcher(template); final StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, Matcher.quoteReplacement(root.get(m.group(1)).asString().get())); } m.appendTail(sb); m = PATTERN_BACKSLASH.matcher(sb.toString()); return m.replaceAll(""); } ValueResolvingFilter(boolean failOnMissingReference);  ValueResolvingFilter(); @Override void init(Config config); @Override String apply(Config.Key key, String stringValue); }
ValueResolvingFilter implements ConfigFilter { private String format(String template) { Matcher m = PATTERN_REFERENCE.matcher(template); final StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, Matcher.quoteReplacement(root.get(m.group(1)).asString().get())); } m.appendTail(sb); m = PATTERN_BACKSLASH.matcher(sb.toString()); return m.replaceAll(""); } ValueResolvingFilter(boolean failOnMissingReference);  ValueResolvingFilter(); @Override void init(Config config); @Override String apply(Config.Key key, String stringValue);  }