I'm using Jimfs in my tests like this:
public class FooTest {
private FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
private List<Path> paths = new ArrayList<>();
private Path getPath(String first, String... more) {
Path path = fs.getPath(first, more);
paths.add(path);
return path;
}
@After public void cleanPaths() {
for (Path path: paths) {
Files.walkFileTree(path, FileVisitors.DELETE);
}
}
@Test public void bar() {
Path baz = getPath("baz");
// test using baz
}
}
Now, we know that Jimfs is in memory. Do I really need to clean up the paths I created or can I just remove the @After
method (and its associated mechanism)?
I clearly think it's the basic need why jimfs was created, but well... I'm adapting existing code and I suddenly became confused about this.