@Test public void load() throws Exception { List<Variable> list = new ArrayList<>(); list.add(new Variable("probe")); list.add(new Variable("mode")); list.add(new Variable("should-have-default", "should have default value", "default")); ConfigurationLoader config = new ConfigurationLoader(list); Map<String, Object> result; try { result = config.loadConfiguration(testYML); } catch (IOException e) { throw new RuntimeException(e); } assertEquals(createTestingProbeList(), result.get("probe")); assertTrue(result.get("probe") instanceof ArrayList); assertEquals("continual", result.get("mode")); assertFalse(result.get("mode") instanceof ArrayList); assertTrue(result.get("mode") instanceof String); assertEquals("default", result.get("should-have-default")); assertFalse(result.get("should-have-default") instanceof ArrayList); assertTrue(result.get("should-have-default") instanceof String); }
public Map<String, Object> loadConfiguration(File file) throws IOException { Map<String, Object> config = new HashMap<>(defaultConfig); Map<String, Object> tmpConfig; try (InputStream input = new FileInputStream(file)) { Yaml yaml = new Yaml(); tmpConfig = yaml.load(input); if (tmpConfig == null) { return config; } for (Map.Entry element : tmpConfig.entrySet()) { String key = (String) element.getKey(); if (!variableNames.contains(key)) { throw new InvalidVariableException("unknown variable: " + key); } else { config.put(key, element.getValue()); } } } return config; }
ConfigurationLoader { public Map<String, Object> loadConfiguration(File file) throws IOException { Map<String, Object> config = new HashMap<>(defaultConfig); Map<String, Object> tmpConfig; try (InputStream input = new FileInputStream(file)) { Yaml yaml = new Yaml(); tmpConfig = yaml.load(input); if (tmpConfig == null) { return config; } for (Map.Entry element : tmpConfig.entrySet()) { String key = (String) element.getKey(); if (!variableNames.contains(key)) { throw new InvalidVariableException("unknown variable: " + key); } else { config.put(key, element.getValue()); } } } return config; } }
ConfigurationLoader { public Map<String, Object> loadConfiguration(File file) throws IOException { Map<String, Object> config = new HashMap<>(defaultConfig); Map<String, Object> tmpConfig; try (InputStream input = new FileInputStream(file)) { Yaml yaml = new Yaml(); tmpConfig = yaml.load(input); if (tmpConfig == null) { return config; } for (Map.Entry element : tmpConfig.entrySet()) { String key = (String) element.getKey(); if (!variableNames.contains(key)) { throw new InvalidVariableException("unknown variable: " + key); } else { config.put(key, element.getValue()); } } } return config; } ConfigurationLoader(List<Variable> variables); }
ConfigurationLoader { public Map<String, Object> loadConfiguration(File file) throws IOException { Map<String, Object> config = new HashMap<>(defaultConfig); Map<String, Object> tmpConfig; try (InputStream input = new FileInputStream(file)) { Yaml yaml = new Yaml(); tmpConfig = yaml.load(input); if (tmpConfig == null) { return config; } for (Map.Entry element : tmpConfig.entrySet()) { String key = (String) element.getKey(); if (!variableNames.contains(key)) { throw new InvalidVariableException("unknown variable: " + key); } else { config.put(key, element.getValue()); } } } return config; } ConfigurationLoader(List<Variable> variables); Map<String, Object> loadConfiguration(File file); }
ConfigurationLoader { public Map<String, Object> loadConfiguration(File file) throws IOException { Map<String, Object> config = new HashMap<>(defaultConfig); Map<String, Object> tmpConfig; try (InputStream input = new FileInputStream(file)) { Yaml yaml = new Yaml(); tmpConfig = yaml.load(input); if (tmpConfig == null) { return config; } for (Map.Entry element : tmpConfig.entrySet()) { String key = (String) element.getKey(); if (!variableNames.contains(key)) { throw new InvalidVariableException("unknown variable: " + key); } else { config.put(key, element.getValue()); } } } return config; } ConfigurationLoader(List<Variable> variables); Map<String, Object> loadConfiguration(File file);  }