From 449acd77579723c8c301a2be8081bbcb4b03665c Mon Sep 17 00:00:00 2001 From: Toke Eskildsen Date: Mon, 22 Mar 2021 12:37:04 +0100 Subject: [PATCH] Add unit-test demonstrating the problem from issue #18 --- src/test/java/dk/kb/util/yaml/YAMLTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/java/dk/kb/util/yaml/YAMLTest.java b/src/test/java/dk/kb/util/yaml/YAMLTest.java index d71ec6cd..27c16199 100644 --- a/src/test/java/dk/kb/util/yaml/YAMLTest.java +++ b/src/test/java/dk/kb/util/yaml/YAMLTest.java @@ -104,6 +104,21 @@ public void testMultiConfig() throws IOException { "The merged YAML should have the expected value for alias-using 'theServer'"); } + @Test + public void testMerge() throws IOException { + final String FIRST_ONLY = "upperA.subYAML.sub2Element"; + assertTrue(YAML.resolveMultiConfig("yaml/overwrite-1.yaml").containsKey(FIRST_ONLY), + "Non-merged first file should contain element '" + FIRST_ONLY + "'"); + + YAML yaml = YAML.resolveMultiConfig("yaml/overwrite-1.yaml", "yaml/overwrite-2.yaml"); + assertEquals("baz", yaml.getString("upperA.subElement"), + "Merged YAML should contain overwritten element 'upperA.subElement'"); + assertEquals("bar", yaml.getString(FIRST_ONLY), + "Merged YAML should contain element '" + FIRST_ONLY + "' from file #1"); + assertEquals(12, yaml.getInteger("upperC.subCElement"), + "Merged YAML should contain element 'upperC.subClement' from file #2"); + } + @Test public void testFailingMultiConfig() throws IOException { Assertions.assertThrows(FileNotFoundException.class,