Skip to content

Commit 5204925

Browse files
author
Gabriel Einsdorf
committed
FileHandleTest: Ensure we do not create ghost files anymore
1 parent 3834df7 commit 5204925

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/test/java/org/scijava/io/handle/FileHandleTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,23 @@ public void testExists() throws IOException {
8989
// Clean up.
9090
assertTrue(nonExistentFile.delete());
9191
}
92+
93+
@Test
94+
public void testNotCreatedByClose() throws IOException {
95+
final Context ctx = new Context();
96+
final DataHandleService dhs = ctx.service(DataHandleService.class);
97+
98+
final File nonExistentFile = //
99+
File.createTempFile("FileHandleTest", "nonexistent-file");
100+
assertTrue(nonExistentFile.delete());
101+
assertFalse(nonExistentFile.exists());
102+
103+
final FileLocation loc = new FileLocation(nonExistentFile);
104+
final DataHandle<?> handle = dhs.create(loc);
105+
assertTrue(handle instanceof FileHandle);
106+
assertFalse(handle.exists());
107+
108+
handle.close();
109+
assertFalse(nonExistentFile.exists());
110+
}
92111
}

0 commit comments

Comments
 (0)