2222 */
2323
2424/* @test
25- * @bug 4842706 8024695 8361587
25+ * @bug 4842706 8024695 8361587 8362429
2626 * @summary Test some file operations with empty path
2727 * @run junit EmptyPath
2828 */
2929
3030import java .io .File ;
31+ import java .io .FileFilter ;
3132import java .io .FileInputStream ;
33+ import java .io .FilenameFilter ;
3234import java .io .FileNotFoundException ;
3335import java .io .IOException ;
36+ import java .net .MalformedURLException ;
3437import java .nio .file .Files ;
3538import java .nio .file .FileStore ;
3639import java .nio .file .Path ;
3740import java .util .Arrays ;
3841import java .util .HashSet ;
3942import java .util .List ;
4043import java .util .Set ;
44+ import java .util .function .Function ;
4145import java .util .stream .Collectors ;
4246
4347import org .junit .jupiter .api .BeforeAll ;
@@ -211,7 +215,15 @@ public void length() throws IOException {
211215
212216 @ Test
213217 public void list () throws IOException {
214- String [] files = f .list ();
218+ list (f .list ());
219+ }
220+
221+ @ Test
222+ public void listFilenameFilter () throws IOException {
223+ list (f .list ((FilenameFilter )null ));
224+ }
225+
226+ private void list (String [] files ) throws IOException {
215227 assertNotNull (files );
216228 Set <String > ioSet = new HashSet (Arrays .asList (files ));
217229 Set <String > nioSet = new HashSet ();
@@ -221,11 +233,42 @@ public void list() throws IOException {
221233
222234 @ Test
223235 public void listFiles () throws IOException {
224- File child = new File (f .getAbsoluteFile (), "child" );
236+ listFiles (x -> x .listFiles ());
237+ }
238+
239+ @ Test
240+ public void listFilesFileFilter () throws IOException {
241+ FileFilter ff = new FileFilter () {
242+ public boolean accept (File pathname ) { return true ; }
243+ };
244+ listFiles (x -> x .listFiles (ff ));
245+ }
246+
247+ @ Test
248+ public void listFilesNullFileFilter () throws IOException {
249+ listFiles (x -> x .listFiles ((FileFilter )null ));
250+ }
251+
252+ @ Test
253+ public void listFilesFilenameFilter () throws IOException {
254+ FilenameFilter fnf = new FilenameFilter () {
255+ public boolean accept (File dir , String name ) { return true ; }
256+ };
257+ listFiles (x -> x .listFiles (fnf ));
258+ }
259+
260+ @ Test
261+ public void listFilesNullFilenameFilter () throws IOException {
262+ listFiles (x -> x .listFiles ((FilenameFilter )null ));
263+ }
264+
265+ private void listFiles (Function <File ,File []> func ) throws IOException {
266+ String childName = "child" + System .nanoTime ();
267+ File child = new File (f .getAbsoluteFile (), childName );
225268 assertTrue (child .createNewFile ());
226269 child .deleteOnExit ();
227270
228- File [] files = f . listFiles ( );
271+ File [] files = func . apply ( f );
229272 for (File file : files )
230273 assertEquals (-1 , f .toString ().indexOf (File .separatorChar ));
231274
@@ -348,4 +391,9 @@ public String toString() {
348391 public void toURI () {
349392 assertEquals (f .toPath ().toUri (), f .toURI ());
350393 }
394+
395+ @ Test
396+ public void toURL () throws MalformedURLException {
397+ assertEquals (f .toPath ().toUri ().toURL (), f .toURL ());
398+ }
351399}
0 commit comments