@Test(timeout = 5000)
public void testPrepareWorkingDir() throws Exception {

  Configuration conf = new Configuration();
  HadoopArchiveLogs hal = new HadoopArchiveLogs(conf);
  FileSystem fs = FileSystem.getLocal(conf);
  Path workingDir = new Path("target", "testPrepareWorkingDir");
  fs.delete(workingDir, true);
  Assert.assertFalse(fs.exists(workingDir));
  // -force is false and the dir doesn't exist so it will create one
  hal.force = false;
  boolean dirPrepared = hal.prepareWorkingDir(fs, workingDir);
  Assert.assertTrue(dirPrepared);
  Assert.assertTrue(fs.exists(workingDir));
  Assert.assertEquals(
      new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
          !Shell.WINDOWS),
      fs.getFileStatus(workingDir).getPermission());
  // Throw a file in the dir
  Path dummyFile = new Path(workingDir, "dummy.txt");
  fs.createNewFile(dummyFile);
  Assert.assertTrue(fs.exists(dummyFile));
  // -force is false and the dir exists, so nothing will happen and the dummy
  // still exists
  dirPrepared = hal.prepareWorkingDir(fs, workingDir);
  Assert.assertFalse(dirPrepared);
  Assert.assertTrue(fs.exists(workingDir));
  Assert.assertTrue(fs.exists(dummyFile));
  Assert.assertEquals(
      new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
          !Shell.WINDOWS),
      fs.getFileStatus(workingDir).getPermission());
  // -force is true and the dir exists, so it will recreate it and the dummy
  // won't exist anymore
  hal.force = true;
  dirPrepared = hal.prepareWorkingDir(fs, workingDir);
  Assert.assertTrue(dirPrepared);
  Assert.assertTrue(fs.exists(workingDir));
  Assert.assertEquals(
      new FsPermission(FsAction.ALL, FsAction.ALL, FsAction.ALL,
          !Shell.WINDOWS),
      fs.getFileStatus(workingDir).getPermission());
  Assert.assertFalse(fs.exists(dummyFile));
}