@Test public void itThrowsExnOnNonObjectOverride() throws Exception { Assertions.assertThrows(IllegalArgumentException.class, () -> buildConfigSourceProvider(DEFAULT_PATH) .open(JUST_A_STRING_PATH) ); }
@Override public InputStream open(String path) throws IOException { JsonNode originalNode = readFromPath(defaultConfigPath); JsonNode overrideNode = readFromPath(path); if (originalNode.isObject() && overrideNode.isObject()) { ObjectNode original = (ObjectNode) originalNode; ObjectNode override = (ObjectNode) overrideNode; merge(original, override); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); objectMapper.writeTree(yamlFactory.createGenerator(outputStream), original); return new ByteArrayInputStream(outputStream.toByteArray()); } else { throw new IllegalArgumentException("Both configuration files must be objects"); } }
MergingConfigProvider implements ConfigurationSourceProvider { @Override public InputStream open(String path) throws IOException { JsonNode originalNode = readFromPath(defaultConfigPath); JsonNode overrideNode = readFromPath(path); if (originalNode.isObject() && overrideNode.isObject()) { ObjectNode original = (ObjectNode) originalNode; ObjectNode override = (ObjectNode) overrideNode; merge(original, override); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); objectMapper.writeTree(yamlFactory.createGenerator(outputStream), original); return new ByteArrayInputStream(outputStream.toByteArray()); } else { throw new IllegalArgumentException("Both configuration files must be objects"); } } }
MergingConfigProvider implements ConfigurationSourceProvider { @Override public InputStream open(String path) throws IOException { JsonNode originalNode = readFromPath(defaultConfigPath); JsonNode overrideNode = readFromPath(path); if (originalNode.isObject() && overrideNode.isObject()) { ObjectNode original = (ObjectNode) originalNode; ObjectNode override = (ObjectNode) overrideNode; merge(original, override); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); objectMapper.writeTree(yamlFactory.createGenerator(outputStream), original); return new ByteArrayInputStream(outputStream.toByteArray()); } else { throw new IllegalArgumentException("Both configuration files must be objects"); } } MergingConfigProvider(ConfigurationSourceProvider delegate, String defaultConfigPath, ObjectMapper objectMapper, YAMLFactory yamlFactory); }
MergingConfigProvider implements ConfigurationSourceProvider { @Override public InputStream open(String path) throws IOException { JsonNode originalNode = readFromPath(defaultConfigPath); JsonNode overrideNode = readFromPath(path); if (originalNode.isObject() && overrideNode.isObject()) { ObjectNode original = (ObjectNode) originalNode; ObjectNode override = (ObjectNode) overrideNode; merge(original, override); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); objectMapper.writeTree(yamlFactory.createGenerator(outputStream), original); return new ByteArrayInputStream(outputStream.toByteArray()); } else { throw new IllegalArgumentException("Both configuration files must be objects"); } } MergingConfigProvider(ConfigurationSourceProvider delegate, String defaultConfigPath, ObjectMapper objectMapper, YAMLFactory yamlFactory); @Override InputStream open(String path); }
MergingConfigProvider implements ConfigurationSourceProvider { @Override public InputStream open(String path) throws IOException { JsonNode originalNode = readFromPath(defaultConfigPath); JsonNode overrideNode = readFromPath(path); if (originalNode.isObject() && overrideNode.isObject()) { ObjectNode original = (ObjectNode) originalNode; ObjectNode override = (ObjectNode) overrideNode; merge(original, override); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); objectMapper.writeTree(yamlFactory.createGenerator(outputStream), original); return new ByteArrayInputStream(outputStream.toByteArray()); } else { throw new IllegalArgumentException("Both configuration files must be objects"); } } MergingConfigProvider(ConfigurationSourceProvider delegate, String defaultConfigPath, ObjectMapper objectMapper, YAMLFactory yamlFactory); @Override InputStream open(String path);  }