@Test
public void testOutputPathValidity() throws Exception {

  final String inputPathStr = inputPath.toUri().getPath();
  final URI uri = fs.getUri();
  final String harName = "foo.har";
  System.setProperty(HadoopArchives.TEST_HADOOP_ARCHIVES_JAR_PATH,
      HADOOP_ARCHIVES_JAR);
  final HadoopArchives har = new HadoopArchives(conf);
  PrintStream stderr = System.err;
  ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
  PrintStream newErr = new PrintStream(byteStream);
  System.setErr(newErr);
  // fail if the archive path already exists
  createFile(archivePath, fs, harName);
  final String[] args = { "-archiveName", harName, "-p", inputPathStr, "*",
      archivePath.toString() };
  Assert.assertEquals(-1, ToolRunner.run(har, args));
  String output = byteStream.toString();
  final Path outputPath = new Path(archivePath, harName);
  Assert.assertTrue(output.indexOf("Archive path: " + outputPath.toString()
      + " already exists") != -1);
  byteStream.reset();
  // fail if the destination directory is a file
  createFile(archivePath, fs, "sub1");
  final Path archivePath2 = new Path(archivePath, "sub1");
  final String[] args2 = { "-archiveName", harName, "-p", inputPathStr, "*",
      archivePath2.toString() };
  Assert.assertEquals(-1, ToolRunner.run(har, args2));
  output = byteStream.toString();
  Assert.assertTrue(output.indexOf("Destination " + archivePath2.toString()
      + " should be a directory but is a file") != -1);
  System.setErr(stderr);
}