### Question:
GlobalConfiguration { public static Configuration loadConfiguration() { final String configDir = System.getenv(ConfigConstants.ENV_FLINK_CONF_DIR); if (configDir == null) { return new Configuration(); } return loadConfiguration(configDir, null); } private  GlobalConfiguration(); static Configuration loadConfiguration(); static Configuration loadConfiguration(final String configDir); static Configuration loadConfiguration(final String configDir, @Nullable final Configuration dynamicProperties); static Configuration loadConfigurationWithDynamicProperties(Configuration dynamicProperties); static boolean isSensitive(String key); static final String FLINK_CONF_FILENAME; static final String HIDDEN_CONTENT; }### Answer:
@Test public void testConfigurationYAML() { File tmpDir = tempFolder.getRoot(); File confFile = new File(tmpDir, GlobalConfiguration.FLINK_CONF_FILENAME); try { try (final PrintWriter pw = new PrintWriter(confFile)) { pw.println("###########################"); pw.println("# Some : comments : to skip"); pw.println("###########################"); pw.println("mykey1: myvalue1"); pw.println("mykey2 : myvalue2"); pw.println("mykey3:myvalue3"); pw.println(" some nonsense without colon and whitespace separator"); pw.println(" : "); pw.println(" "); pw.println(" "); pw.println("mykey4: myvalue4# some comments"); pw.println(" mykey5 : myvalue5 "); pw.println("mykey6: my: value6"); pw.println("mykey7: "); pw.println(": myvalue8"); pw.println("mykey9: myvalue9"); pw.println("mykey9: myvalue10"); } catch (FileNotFoundException e) { e.printStackTrace(); } Configuration conf = GlobalConfiguration.loadConfiguration(tmpDir.getAbsolutePath()); assertEquals(6, conf.keySet().size()); assertEquals("myvalue1", conf.getString("mykey1", null)); assertEquals("myvalue2", conf.getString("mykey2", null)); assertEquals("null", conf.getString("mykey3", "null")); assertEquals("myvalue4", conf.getString("mykey4", null)); assertEquals("myvalue5", conf.getString("mykey5", null)); assertEquals("my: value6", conf.getString("mykey6", null)); assertEquals("null", conf.getString("mykey7", "null")); assertEquals("null", conf.getString("mykey8", "null")); assertEquals("myvalue10", conf.getString("mykey9", null)); } finally { confFile.delete(); tmpDir.delete(); } }
@Test(expected = IllegalArgumentException.class) public void testFailIfNull() { GlobalConfiguration.loadConfiguration(null); }
@Test(expected = IllegalConfigurationException.class) public void testFailIfNotLoaded() { GlobalConfiguration.loadConfiguration("/some/path/" + UUID.randomUUID()); }
@Test(expected = IllegalConfigurationException.class) public void testInvalidConfiguration() throws IOException { GlobalConfiguration.loadConfiguration(tempFolder.getRoot().getAbsolutePath()); }
@Test public void testInvalidYamlFile() throws IOException { final File confFile = tempFolder.newFile(GlobalConfiguration.FLINK_CONF_FILENAME); try (PrintWriter pw = new PrintWriter(confFile)) { pw.append("invalid"); } assertNotNull(GlobalConfiguration.loadConfiguration(tempFolder.getRoot().getAbsolutePath())); }