### Question:
LauncherMain { static FileOutputStream createStreamIfFileNotExists(File output) throws IOException { if (output.exists()) { System.out.println(output + " exists, skipping. The action will use the " + output.getName() + " defined in the workflow."); return null; } else { System.out.println("Creating " + output.getAbsolutePath()); return new FileOutputStream(output); } }  static Set<ApplicationId> getChildYarnJobs(Configuration actionConf); static Set<ApplicationId> getChildYarnJobs(Configuration actionConf, ApplicationsRequestScope scope,
                                                      long startTime); static Set<ApplicationId> getChildYarnJobs(Configuration actionConf, ApplicationsRequestScope scope); static List<ApplicationReport> getChildYarnApplications(final Configuration actionConf,
                                                                   final ApplicationsRequestScope scope,
                                                                   long startTime); static void killChildYarnJobs(Configuration actionConf); static Configuration loadActionConf(); void propagateToHadoopConf(); static final String ACTION_PREFIX; static final String EXTERNAL_CHILD_IDS; static final String EXTERNAL_ACTION_STATS; static final String EXTERNAL_STATS_WRITE; static final String OUTPUT_PROPERTIES; static final String HADOOP_JOBS; static final String MAPREDUCE_JOB_TAGS; static final String CHILD_MAPREDUCE_JOB_TAGS; static final String OOZIE_JOB_LAUNCH_TIME; static final String TEZ_APPLICATION_TAGS; static final String SPARK_YARN_TAGS; static final String PROPAGATION_CONF_XML; }### Answer:
@Test public void testDontCreateStreamIfFileExists() throws IOException { File f = tmp.newFile(); try (FileOutputStream fos = new FileOutputStream(f)) { fos.write("foo".getBytes(StandardCharsets.UTF_8)); } try (FileOutputStream fos = LauncherMain.createStreamIfFileNotExists(f)) { assertNull(fos); } }
@Test public void testConfigWrite() throws IOException { File f = new File(tmp.newFolder(), "nonExistentFile"); assertFalse(f.exists()); try (FileOutputStream fos = LauncherMain.createStreamIfFileNotExists(f)) { Configuration c = new Configuration(false); c.set("foo", "bar"); c.writeXml(fos); } String contents = new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8); assertTrue(contents.contains("foo")); assertTrue(contents.contains("bar")); assertTrue(contents.contains("<configuration>")); assertTrue(contents.contains("<property")); }
@Test public void testPropertiesWrite() throws IOException { File f = new File(tmp.newFolder(), "nonExistentFile"); assertFalse(f.exists()); try (FileOutputStream fos = LauncherMain.createStreamIfFileNotExists(f)) { Properties p = new Properties(); p.setProperty("foo", "bar"); p.store(fos, ""); } String contents = new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8); assertTrue(contents.contains("foo=bar")); }