### Question:
ConfigurationParser { public C parse(ConfigurationSource provider) { LOGGER.debug("Parsing configuration in format={} from source={}", format, provider); C configuration = doParse(provider).withOverrides(overrides); PlaceholderResolutionResult<C> resolved = configuration.resolvePlaceholders(overrides); if (!resolved.unresolvedPlaceholders().isEmpty()) { throw new IllegalStateException(format("Unresolved placeholders: %s", resolved.unresolvedPlaceholders())); } return resolved.resolvedConfiguration(); } private  ConfigurationParser(Builder<C> builder); C parse(ConfigurationSource provider);  }### Answer:
@Test public void providesConfig() { createStubConfig("/fake/simple-config.yml", ImmutableMap.of( "foo", 123, "bar", "abc")); ConfigurationParser<StubConfiguration> parser = new ConfigurationParser.Builder<StubConfiguration>() .format(format) .build(); StubConfiguration parsedConfiguration = parser.parse(configSource(newResource("/fake/simple-config.yml"))); assertThat(parsedConfiguration.get("bar"), isValue("abc")); assertThat(parsedConfiguration.get("foo", Integer.class), isValue(123)); }
@Test public void includesParent() { ConfigurationParser<StubConfiguration> parser = new ConfigurationParser.Builder<StubConfiguration>() .format(format) .build(); StubConfiguration parsedConfiguration = parser.parse(configSource(newResource("/fake/base-config.yml"))); assertThat(parsedConfiguration.get("string"), isValue("abc")); assertThat(parsedConfiguration.get("stringFromParent"), isValue("DEF")); assertThat(parsedConfiguration.get("numberFromParent", Integer.class), isValue(999)); }
@Test public void includedValuesCanBeOverridden() { ConfigurationParser<StubConfiguration> parser = new ConfigurationParser.Builder<StubConfiguration>() .format(format) .build(); StubConfiguration parsedConfiguration = parser.parse(configSource(newResource("/fake/base-config.yml"))); assertThat(parsedConfiguration.get("string"), isValue("abc")); assertThat(parsedConfiguration.get("stringFromParent"), isValue("DEF")); assertThat(parsedConfiguration.get("numberFromParent", Integer.class), isValue(999)); }
@Test public void resolvesPlaceholdersInConfig() { ConfigurationParser<StubConfiguration> parser = new ConfigurationParser.Builder<StubConfiguration>() .format(format) .build(); StubConfiguration parsedConfiguration = parser.parse(configSource(newResource("/fake/base-config.yml"))); assertThat(parsedConfiguration.get("hasPlaceholder"), isValue("abc")); }
@Test public void appliesOverrides() { ConfigurationParser<StubConfiguration> parser = new ConfigurationParser.Builder<StubConfiguration>() .format(format) .overrides(ImmutableMap.of("string", "overridden")) .build(); StubConfiguration parsedConfiguration = parser.parse(configSource(newResource("/fake/base-config.yml"))); assertThat(parsedConfiguration.get("string"), isValue("overridden")); }
@Test public void includeValueCanContainPlaceholder() { createStubConfig("/test/base-config.yml", ImmutableMap.of( "include", "${include-placeholder}", "number", 123, "string", "abc", "numberFromParent", 999, "hasPlaceholder", "${string}" )); createStubConfig("/test/parent-config.yml", ImmutableMap.of( "numberFromParent", 111, "stringFromParent", "DEF")); ConfigurationParser<StubConfiguration> parser = new ConfigurationParser.Builder<StubConfiguration>() .format(format) .overrides(ImmutableMap.of("include-placeholder", "/test/parent-config.yml")) .build(); StubConfiguration parsedConfiguration = parser.parse(configSource(newResource("/test/base-config.yml"))); assertThat(parsedConfiguration.get("stringFromParent"), isValue("DEF")); }
@Test public void childCanReplaceParentPlaceholders() { createStubConfig("/test/base-config.yml", ImmutableMap.of( "include", "/test/parent-config.yml", "childString", "abc" )); createStubConfig("/test/parent-config.yml", ImmutableMap.of( "parentString", "${childString}" )); ConfigurationParser<StubConfiguration> parser = new ConfigurationParser.Builder<StubConfiguration>() .format(format) .build(); StubConfiguration parsedConfiguration = parser.parse(configSource(newResource("/test/base-config.yml"))); assertThat(parsedConfiguration.get("parentString"), isValue("abc")); }