Skip to content

Commit

Permalink
Merge pull request #122 from cfg4j/support-empty-yaml
Browse files Browse the repository at this point in the history
support empty yaml documents
  • Loading branch information
norbertpotocki committed Nov 3, 2015
2 parents d6947f6 + 2798190 commit 20f1d7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
Expand Up @@ -53,8 +53,10 @@ public Properties getProperties(InputStream inputStream) {

Object object = yaml.load(reader);

Map<String, Object> yamlAsMap = convertToMap(object);
properties.putAll(flatten(yamlAsMap));
if (object != null) {
Map<String, Object> yamlAsMap = convertToMap(object);
properties.putAll(flatten(yamlAsMap));
}

return properties;

Expand Down
Expand Up @@ -101,6 +101,15 @@ public void shouldThrowForNonYamlFile() throws Exception {
expectedException.expect(IllegalStateException.class);
provider.getProperties(input);
}
}

@Test
public void shouldSupportEmptyDocument() throws Exception {
String path = "org/cfg4j/source/propertiesprovider/YamlBasedPropertiesProviderTest_shouldSupportEmptyDocument.yaml";

try (InputStream input = getClass().getClassLoader().getResourceAsStream(path)) {
assertThat(provider.getProperties(input)).isEmpty();
}

}
}

0 comments on commit 20f1d7f

Please sign in to comment.