@Test(expected = InvalidVariableException.class) public void invalidVariable() throws Exception { List<Variable> variables = Collections.singletonList(new Variable("allowed")); (new ConfigurationLoader(variables)).loadConfiguration(testYML); }
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);  }