zhuzhurk commented on a change in pull request #9950: [FLINK-14464][runtime] Introduce the AbstractUserClassPathJobGraphRetriever URL: https://github.com/apache/flink/pull/9950#discussion_r339283968
########## File path: flink-core/src/test/java/org/apache/flink/util/FileUtilsTest.java ########## @@ -259,6 +267,67 @@ public void testCompression() throws IOException { assertDirEquals(compressDir.resolve(originalDir), extractDir.resolve(originalDir)); } + @Test + public void testListFilesInPathWithoutAnyFileReturnEmptyList() throws IOException { + final java.nio.file.Path testDir = tmp.newFolder("_test_0").toPath(); + + assertTrue(Collections.<File>emptyList() == + FileUtils.listFilesInPath(testDir.toFile(), f -> f.getName().endsWith(".jar"))); + } + + @Test + public void testListFilesInPath() throws IOException { + final java.nio.file.Path testDir = tmp.newFolder("_test_1").toPath(); + final Tuple3<Collection<File>, Collection<File>, Collection<URL>> result = prepareTestFiles(testDir); + + assertTrue(CollectionUtils.isEqualCollection(result.f0, + FileUtils.listFilesInPath(testDir.toFile(), f -> f.getName().endsWith(".jar")))); + } + + @Test + public void testRelativizeToWorkingDir() throws IOException { + final java.nio.file.Path testDir = tmp.newFolder("_test_2").toPath(); + final Tuple3<Collection<File>, Collection<File>, Collection<URL>> result = prepareTestFiles(testDir); + final Collection<File> relativeFiles = FileUtils.relativizeToWorkingDir(result.f0); + relativeFiles.forEach(file -> assertFalse(file.isAbsolute())); + assertTrue( + CollectionUtils.isEqualCollection( + result.f1, + FileUtils.relativizeToWorkingDir(result.f0) + ) + ); + } + + @Test + public void testToRelativeURLs() throws IOException { + final java.nio.file.Path testDir = tmp.newFolder("_test_3").toPath(); + final Tuple3<Collection<File>, Collection<File>, Collection<URL>> result = prepareTestFiles(testDir); + + final Collection<URL> relativeURLs = FileUtils.toRelativeURLs(result.f1); + relativeURLs.forEach(url -> assertFalse(new File(url.getPath()).isAbsolute())); + + assertTrue( + CollectionUtils.isEqualCollection( + result.f2, + relativeURLs + ) + ); + } + + @Test(expected = IllegalArgumentException.class) + public void testListDirFailsIfDirectoryDoesNotExist() throws IOException { + final String fileName = "_does_not_exists_file"; + final String doesNotExistsFilePath = tmp.getRoot() + "/" + fileName; + + FileUtils.listFilesInPath(new File(doesNotExistsFilePath), f -> f.getName().endsWith(".jar")); + } + + @Test(expected = IllegalArgumentException.class) + public void testListAFileFailsBecauseDirectoryIsExpected() throws IOException { Review comment: maybe testListAFileFailsBecauseDirectoryIsExpected -> testListDirFailsIfParamIsNotDirectory ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services