2222 */
2323
2424/* @test
25- * @bug 4842706 8024695
25+ * @bug 4842706 8024695 8361587
2626 * @summary Test some file operations with empty path
2727 * @run junit EmptyPath
2828 */
3636import java .nio .file .Path ;
3737import java .util .Arrays ;
3838import java .util .HashSet ;
39+ import java .util .List ;
3940import java .util .Set ;
41+ import java .util .stream .Collectors ;
4042
4143import org .junit .jupiter .api .BeforeAll ;
4244import org .junit .jupiter .api .Test ;
4345
4446import org .junit .jupiter .api .condition .DisabledOnOs ;
45- import org .junit .jupiter .api .condition .EnabledOnOs ;
4647import org .junit .jupiter .api .condition .OS ;
4748
4849import static org .junit .jupiter .api .Assertions .*;
@@ -105,13 +106,28 @@ public void exists() {
105106 assertTrue (f .exists ());
106107 }
107108
109+ @ Test
110+ public void getAbsoluteFile () {
111+ assertEquals (p .toAbsolutePath ().toFile (), f .getAbsoluteFile ());
112+ }
113+
108114 @ Test
109115 public void getAbsolutePath () {
110116 System .out .println (p .toAbsolutePath ().toString () + "\n " +
111117 f .getAbsolutePath ());
112118 assertEquals (p .toAbsolutePath ().toString (), f .getAbsolutePath ());
113119 }
114120
121+ @ Test
122+ public void getCanonicalFile () throws IOException {
123+ assertEquals (p .toRealPath ().toFile (), f .getCanonicalFile ());
124+ }
125+
126+ @ Test
127+ public void getCanonicalPath () throws IOException {
128+ assertEquals (p .toRealPath ().toString (), f .getCanonicalPath ());
129+ }
130+
115131 private void checkSpace (long expected , long actual ) {
116132 if (expected == 0 ) {
117133 assertEquals (0L , actual );
@@ -136,6 +152,11 @@ public void getParent() {
136152 assertNull (f .getParent ());
137153 }
138154
155+ @ Test
156+ public void getParentFile () {
157+ assertNull (f .getParentFile ());
158+ }
159+
139160 @ Test
140161 public void getPath () {
141162 assertEquals (p .toString (), f .getPath ());
@@ -198,11 +219,57 @@ public void list() throws IOException {
198219 assertEquals (nioSet , ioSet );
199220 }
200221
222+ @ Test
223+ public void listFiles () throws IOException {
224+ File child = new File (f .getAbsoluteFile (), "child" );
225+ assertTrue (child .createNewFile ());
226+ child .deleteOnExit ();
227+
228+ File [] files = f .listFiles ();
229+ for (File file : files )
230+ assertEquals (-1 , f .toString ().indexOf (File .separatorChar ));
231+
232+ Set <String > ioSet = Arrays .stream (files )
233+ .map (File ::getName )
234+ .collect (Collectors .toSet ());
235+
236+ assertTrue (ioSet .contains (child .getName ()));
237+
238+ Set <String > nioSet = Files .list (p )
239+ .map (Path ::getFileName )
240+ .map (Path ::toString )
241+ .collect (Collectors .toSet ());
242+ assertEquals (nioSet , ioSet );
243+ }
244+
245+ @ Test
246+ public void listRoots () {
247+ Set <String > expected = Arrays .stream (f .getAbsoluteFile ().listRoots ())
248+ .map (File ::toString )
249+ .collect (Collectors .toSet ());
250+ Set <String > actual = Arrays .stream (f .listRoots ())
251+ .map (File ::toString )
252+ .collect (Collectors .toSet ());
253+ assertEquals (expected , actual );
254+ }
255+
201256 @ Test
202257 public void mkdir () {
203258 assertFalse (f .mkdir ());
204259 }
205260
261+ @ Test
262+ public void mkdirs () {
263+ assertFalse (f .mkdirs ());
264+ }
265+
266+ @ Test
267+ public void renameTo () throws IOException {
268+ File tmp = File .createTempFile ("foo" , "bar" , f .getAbsoluteFile ());
269+ assertTrue (tmp .exists ());
270+ assertFalse (f .renameTo (tmp ));
271+ }
272+
206273 @ Test
207274 public void setLastModified () {
208275 long t0 = f .lastModified ();
@@ -271,6 +338,12 @@ public void toPath() {
271338 assertEquals (p , f .toPath ());
272339 }
273340
341+ @ Test
342+ public String toString () {
343+ assertEquals (EMPTY_STRING , f .toString ());
344+ return EMPTY_STRING ;
345+ }
346+
274347 @ Test
275348 public void toURI () {
276349 assertEquals (f .toPath ().toUri (), f .toURI ());
0 commit comments