@Test
public void testJarsDeDupe() throws IOException {

  final File tempDir = getLocalTempDir();
  // Jar list should de-dupe to {"myjar_a, "myjar_b", "myjar_0", "myjar_1"}
  Set<String> dedupedJarNames = new HashSet<String>(4);
  dedupedJarNames.add("myjar_a.jar");
  dedupedJarNames.add("myjar_b.jar");
  dedupedJarNames.add("myjar_0.jar");
  dedupedJarNames.add("myjar_1.jar");
  Job job = new Job();
  List<String> someJars = new ArrayList<String>();
  // Some unique jar names.
  someJars.add("/somepath/myjar_a.jar");
  someJars.add("/another/path/myjar_b.jar");
  someJars.add("/myjar_0.jar");
  // Duplicate jars.
  someJars.add("/another/path/myjar_b.jar");
  someJars.add("/yet/another/path/myjar_b.jar");
  job.getConfiguration().set(CONF_TMPJARS, StringUtils.join(someJars, ","));
  // Now add some duplicate jars from mTempDir.
  assertEquals(0, tempDir.list().length);
  createTestJars(tempDir, "myjar_0.jar", "myjar_1.jar");
  assertEquals(2, tempDir.list().length);
  DistributedCacheJars.addJarsToDistributedCache(job, tempDir);
  // Confirm each jar appears in de-dupe list exactly once.
  String listedJars = job.getConfiguration().get(CONF_TMPJARS);
  String[] jars = listedJars.split(",");
  for (String jar : jars) {
    // Check that path terminates in an expected jar.
    Path p = new Path(jar);
    assertTrue(dedupedJarNames.contains(p.getName()));
    dedupedJarNames.remove(p.getName());
  }
  assertEquals(0, dedupedJarNames.size());
}