@Test(timeout=10000)
public void testBuildListing() {

  FileSystem fs = null;
  try {
    fs = FileSystem.get(getConf());
    List<Path> srcPaths = new ArrayList<Path>();
    Path p1 = new Path("/tmp/in/1");
    Path p2 = new Path("/tmp/in/2");
    Path p3 = new Path("/tmp/in2/2");
    Path target = new Path("/tmp/out/1");
    srcPaths.add(p1.getParent());
    srcPaths.add(p3.getParent());
    TestDistCpUtils.createFile(fs, "/tmp/in/1");
    TestDistCpUtils.createFile(fs, "/tmp/in/2");
    TestDistCpUtils.createFile(fs, "/tmp/in2/2");
    fs.mkdirs(target);
    OutputStream out = fs.create(p1);
    out.write("ABC".getBytes());
    out.close();
    out = fs.create(p2);
    out.write("DEF".getBytes());
    out.close();
    out = fs.create(p3);
    out.write("GHIJ".getBytes());
    out.close();
    Path listingFile = new Path("/tmp/file");
    DistCpOptions options = new DistCpOptions(srcPaths, target);
    options.setSyncFolder(true);
    CopyListing listing = new SimpleCopyListing(getConf(), CREDENTIALS);
    try {
      listing.buildListing(listingFile, options);
      Assert.fail("Duplicates not detected");
    } catch (DuplicateFileException ignore) {
    }
    Assert.assertEquals(listing.getBytesToCopy(), 10);
    Assert.assertEquals(listing.getNumberOfPaths(), 3);
    TestDistCpUtils.delete(fs, "/tmp");
    try {
      listing.buildListing(listingFile, options);
      Assert.fail("Invalid input not detected");
    } catch (InvalidInputException ignore) {
    }
    TestDistCpUtils.delete(fs, "/tmp");
  } catch (IOException e) {
    LOG.error("Exception encountered ", e);
    Assert.fail("Test build listing failed");
  } finally {
    TestDistCpUtils.delete(fs, "/tmp");
  }
}