@Test
public void testAddFileToClassPath() throws Exception {

  Configuration conf = new Configuration(false);
  // Test first with 2 args
  try {
    DistributedCache.addFileToClassPath(null, conf);
    fail("Accepted null archives argument");
  } catch (NullPointerException ex) {
    // Expected
  }
  DistributedCache.addFileToClassPath(new Path("file:///a"), conf);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a", conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "file:///a", conf.get(MRJobConfig.CACHE_FILES));
  DistributedCache.addFileToClassPath(new Path("file:///b"), conf);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a,file:/b",
      conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "file:///a,file:///b",
      conf.get(MRJobConfig.CACHE_FILES));
  // Now test with 3 args
  FileSystem fs = FileSystem.newInstance(conf);
  conf.clear();
  try {
    DistributedCache.addFileToClassPath(null, conf, fs);
    fail("Accepted null archives argument");
  } catch (NullPointerException ex) {
    // Expected
  }
  DistributedCache.addFileToClassPath(new Path("file:///a"), conf, fs);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a", conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "file:///a", conf.get(MRJobConfig.CACHE_FILES));
  DistributedCache.addFileToClassPath(new Path("file:///b"), conf, fs);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a,file:/b",
      conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "file:///a,file:///b",
      conf.get(MRJobConfig.CACHE_FILES));
  // Now test with 4th arg true
  conf.clear();
  try {
    DistributedCache.addFileToClassPath(null, conf, fs, true);
    fail("Accepted null archives argument");
  } catch (NullPointerException ex) {
    // Expected
  }
  DistributedCache.addFileToClassPath(new Path("file:///a"), conf, fs, true);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a", conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "file:///a", conf.get(MRJobConfig.CACHE_FILES));
  DistributedCache.addFileToClassPath(new Path("file:///b"), conf, fs, true);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a,file:/b",
      conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "file:///a,file:///b",
      conf.get(MRJobConfig.CACHE_FILES));
  // And finally with 4th arg false
  conf.clear();
  try {
    DistributedCache.addFileToClassPath(null, conf, fs, false);
    fail("Accepted null archives argument");
  } catch (NullPointerException ex) {
    // Expected
  }
  DistributedCache.addFileToClassPath(new Path("file:///a"), conf, fs, false);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a", conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "", conf.get(MRJobConfig.CACHE_FILES, ""));
  DistributedCache.addFileToClassPath(new Path("file:///b"), conf, fs, false);
  assertEquals("The mapreduce.job.classpath.files property was not "
      + "set correctly", "file:/a,file:/b",
      conf.get(MRJobConfig.CLASSPATH_FILES));
  assertEquals("The mapreduce.job.cache.files property was not set "
      + "correctly", "", conf.get(MRJobConfig.CACHE_FILES, ""));
}