4646import org .scijava .Context ;
4747import org .scijava .io .location .FileLocation ;
4848import org .scijava .io .location .Location ;
49- import org .scijava .util .PlatformUtils ;
5049
5150/**
5251 * Tests {@link FileHandle}.
@@ -76,23 +75,22 @@ public void testExists() throws IOException {
7675
7776 final File nonExistentFile = //
7877 File .createTempFile ("FileHandleTest" , "nonexistent-file" );
79- final boolean deleted = delete (nonExistentFile );
78+ assertTrue (nonExistentFile .delete ());
79+ assertFalse (nonExistentFile .exists ());
8080
8181 final FileLocation loc = new FileLocation (nonExistentFile );
8282 try (final DataHandle <?> handle = dhs .create (loc )) {
8383 assertTrue (handle instanceof FileHandle );
84- if (deleted ) {
85- assertFalse (handle .exists ());
86- assertEquals (-1 , handle .length ());
87- }
84+ assertFalse (handle .exists ());
85+ assertEquals (-1 , handle .length ());
8886
8987 handle .writeBoolean (true );
9088 assertTrue (handle .exists ());
9189 assertEquals (1 , handle .length ());
9290 }
9391
9492 // Clean up.
95- delete (nonExistentFile );
93+ assertTrue (nonExistentFile . delete () );
9694 }
9795
9896 @ Test
@@ -121,7 +119,8 @@ public void testNotCreatedByRead() throws IOException {
121119 final File nonExistentFile = //
122120 File .createTempFile ("FileHandleTest" , "none xistent file" );
123121 final URI uri = nonExistentFile .toURI ();
124- delete (nonExistentFile );
122+ assertTrue (nonExistentFile .delete ());
123+ assertFalse (nonExistentFile .exists ());
125124
126125 final FileLocation loc = new FileLocation (uri );
127126 try (final DataHandle <?> handle = dhs .create (loc )) {
@@ -135,15 +134,4 @@ public void testNotCreatedByRead() throws IOException {
135134 assertFalse (nonExistentFile .exists ());
136135 // reading from the non-existing file should not create it!
137136 }
138-
139- /** A workaround for Windows being bad at deleting files. */
140- private boolean delete (final File file ) {
141- final boolean success = file .delete ();
142- if (!success ) file .deleteOnExit ();
143- if (!PlatformUtils .isWindows ()) {
144- assertTrue (success );
145- assertFalse (file .exists ());
146- }
147- return success ;
148- }
149137}
0 commit comments