@Test (timeout = 30000)
public void testCreateJarWithClassPath() throws Exception {

  // setup test directory for files
  Assert.assertFalse(tmp.exists());
  Assert.assertTrue(tmp.mkdirs());
  // create files expected to match a wildcard
  List<File> wildcardMatches = Arrays.asList(new File(tmp, "wildcard1.jar"),
    new File(tmp, "wildcard2.jar"), new File(tmp, "wildcard3.JAR"),
    new File(tmp, "wildcard4.JAR"));
  for (File wildcardMatch: wildcardMatches) {
    Assert.assertTrue("failure creating file: " + wildcardMatch,
      wildcardMatch.createNewFile());
  }
  // create non-jar files, which we expect to not be included in the classpath
  Assert.assertTrue(new File(tmp, "text.txt").createNewFile());
  Assert.assertTrue(new File(tmp, "executable.exe").createNewFile());
  Assert.assertTrue(new File(tmp, "README").createNewFile());
  // create classpath jar
  String wildcardPath = tmp.getCanonicalPath() + File.separator + "*";
  String nonExistentSubdir = tmp.getCanonicalPath() + Path.SEPARATOR + "subdir"
    + Path.SEPARATOR;
  List<String> classPaths = Arrays.asList("", "cp1.jar", "cp2.jar", wildcardPath,
    "cp3.jar", nonExistentSubdir);
  String inputClassPath = StringUtils.join(File.pathSeparator, classPaths);
  String classPathJar = FileUtil.createJarWithClassPath(inputClassPath,
    new Path(tmp.getCanonicalPath()), System.getenv());
  // verify classpath by reading manifest from jar file
  JarFile jarFile = null;
  try {
    jarFile = new JarFile(classPathJar);
    Manifest jarManifest = jarFile.getManifest();
    Assert.assertNotNull(jarManifest);
    Attributes mainAttributes = jarManifest.getMainAttributes();
    Assert.assertNotNull(mainAttributes);
    Assert.assertTrue(mainAttributes.containsKey(Attributes.Name.CLASS_PATH));
    String classPathAttr = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
    Assert.assertNotNull(classPathAttr);
    List<String> expectedClassPaths = new ArrayList<String>();
    for (String classPath: classPaths) {
      if (classPath.length() == 0) {
        continue;
      }
      if (wildcardPath.equals(classPath)) {
        // add wildcard matches
        for (File wildcardMatch: wildcardMatches) {
          expectedClassPaths.add(wildcardMatch.toURI().toURL()
            .toExternalForm());
        }
      } else {
        File fileCp = null;
        if(!new Path(classPath).isAbsolute()) {
          fileCp = new File(tmp, classPath);
        }
        else {
          fileCp = new File(classPath);
        }
        if (nonExistentSubdir.equals(classPath)) {
          // expect to maintain trailing path separator if present in input, even
          // if directory doesn't exist yet
          expectedClassPaths.add(fileCp.toURI().toURL()
            .toExternalForm() + Path.SEPARATOR);
        } else {
          expectedClassPaths.add(fileCp.toURI().toURL()
            .toExternalForm());
        }
      }
    }
    List<String> actualClassPaths = Arrays.asList(classPathAttr.split(" "));
    Collections.sort(expectedClassPaths);
    Collections.sort(actualClassPaths);
    Assert.assertEquals(expectedClassPaths, actualClassPaths);
  } finally {
    if (jarFile != null) {
      try {
        jarFile.close();
      } catch (IOException e) {
        LOG.warn("exception closing jarFile: " + classPathJar, e);
      }
    }
  }
}