Skip to content

Commit a229f90

Browse files
authored
Uncomment and update null tests for FileUtils.toURLs(File...) (#546)
* uncomment and update null tests for toURLs * javadoc
1 parent 9975dd4 commit a229f90

2 files changed

Lines changed: 18 additions & 21 deletions

File tree

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3054,15 +3054,15 @@ public static void touch(final File file) throws IOException {
30543054
}
30553055

30563056
/**
3057-
* Converts each of an array of {@link File} to a {@link URL}.
3057+
* Converts each element of an array of {@link File} to a {@link URL}.
30583058
* <p>
30593059
* Returns an array of the same size as the input.
30603060
* </p>
30613061
*
30623062
* @param files the files to convert, must not be {@code null}
30633063
* @return an array of URLs matching the input
30643064
* @throws IOException if a file cannot be converted
3065-
* @throws NullPointerException if the parameter is null
3065+
* @throws NullPointerException if any argument is null
30663066
*/
30673067
public static URL[] toURLs(final File... files) throws IOException {
30683068
Objects.requireNonNull(files, "files");

src/test/java/org/apache/commons/io/FileUtilsTest.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -791,25 +791,22 @@ public void testCopyDirectoryFiltered() throws IOException {
791791
assertEquals("file3.txt", files.get(2).getName());
792792
}
793793

794-
// @Test public void testToURLs2() throws Exception {
795-
// File[] files = new File[] {
796-
// new File(temporaryFolder, "file1.txt"),
797-
// null,
798-
// };
799-
// URL[] urls = FileUtils.toURLs(files);
800-
//
801-
// assertEquals(files.length, urls.length);
802-
// assertTrue(urls[0].toExternalForm().startsWith("file:"));
803-
// assertTrue(urls[0].toExternalForm().indexOf("file1.txt") > 0);
804-
// assertEquals(null, urls[1]);
805-
// }
806-
//
807-
// @Test public void testToURLs3() throws Exception {
808-
// File[] files = null;
809-
// URL[] urls = FileUtils.toURLs(files);
810-
//
811-
// assertEquals(0, urls.length);
812-
// }
794+
@Test
795+
public void testToURLs2() {
796+
final File[] files = new File[] {
797+
new File(tempDirFile, "file1.txt"),
798+
null,
799+
};
800+
assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files),
801+
"Can't convert null URL");
802+
}
803+
804+
@Test
805+
public void testToURLs3() {
806+
final File[] files = null;
807+
assertThrows(NullPointerException.class, () -> FileUtils.toURLs(files),
808+
"Can't convert null list");
809+
}
813810

814811
@Test
815812
public void testCopyDirectoryPreserveDates() throws Exception {

0 commit comments

Comments
 (0)