### Question:
ClassPaths { public static List<String> getClassPathEntries(String classPath) { List<String> entries = new ArrayList<>(); if(classPath.isEmpty()){ return entries; } for(String rawEntry : classPath.split(File.pathSeparator)) { File file = new File(rawEntry); if(file.exists()) { if(file.isDirectory()) { for(File jarFile : file.listFiles((File f) -> f.isFile() && f.getName().endsWith(".jar"))) { entries.add(jarFile.getAbsolutePath()); } } entries.add(file.getAbsolutePath()); } else { LOG.warn("ClassPath entry {} not found, will skip it.", rawEntry); } } return entries; }  static List<String> getClassPathEntries(String classPath);  }### Answer:
@Test public void testOneEntry() throws IOException { File entry = tmpFolder.newFolder("oneentry"); String rawEntry = entry.getAbsolutePath(); List<String> classPathEntries = ClassPaths.getClassPathEntries(rawEntry); assertThat(classPathEntries, contains(entry.getAbsolutePath())); }
@Test public void tesZeroEntry() { String rawEntry = ""; List<String> classPathEntries = ClassPaths.getClassPathEntries(rawEntry); assertThat(classPathEntries, hasSize(0)); }
@Test public void testMultipleEntry() throws IOException { List<String> entries = Lists.newArrayList(tmpFolder.newFolder("oneentry").getAbsolutePath(), tmpFolder.newFile("twoentry.jar").getAbsolutePath(), tmpFolder.newFolder("threeentry").getAbsolutePath()); String rawEntry = String.join(File.pathSeparator, entries); List<String> classPathEntries = ClassPaths.getClassPathEntries(rawEntry); assertThat(classPathEntries, containsInAnyOrder(entries.toArray(new String[entries.size()]))); }
@Test public void testMultipleEntryWithJars() throws IOException { List<String> entries = Lists.newArrayList(tmpFolder.newFolder("oneentry").getAbsolutePath(), tmpFolder.newFile("twoentry.jar").getAbsolutePath(), tmpFolder.newFolder("threeentry").getAbsolutePath()); entries.set(1, entries.get(1).replace(File.separator + "twoentry.jar", "")); String rawEntry = String.join(File.pathSeparator, entries); entries.add(entries.get(1) + File.separator + "twoentry.jar"); List<String> classPathEntries = ClassPaths.getClassPathEntries(rawEntry); assertThat(classPathEntries, containsInAnyOrder(entries.toArray(new String[entries.size()]))); }
@Test public void testUnexistingFile() throws IOException { List<String> entries = Lists.newArrayList(tmpFolder.newFolder("oneentry").getAbsolutePath(), tmpFolder.newFile("twoentry.jar").getAbsolutePath(), tmpFolder.newFolder("threeentry").getAbsolutePath()); String nonExisting = tmpFolder.newFolder("fourthentry").getAbsolutePath() + File.separator + "nonexisting.jar"; String rawEntry = String.join(File.pathSeparator, entries) + File.pathSeparator + nonExisting; List<String> classPathEntries = ClassPaths.getClassPathEntries(rawEntry); assertThat(classPathEntries, containsInAnyOrder(entries.toArray(new String[entries.size()]))); assertThat(classPathEntries, not(contains(nonExisting))); }