mirror of
https://github.com/cryptomator/cryptomator.git
synced 2026-09-19 22:44:32 +00:00
Fixed NioFileSystemIntegrationTests on windows
* Streams returned from NioFolder#children, files and folders are now closed automatically after a terminal operation * Not closing them lead to a bug on windows causing directories to be not deleted after a successful Files.delete invocation
This commit is contained in:
@@ -9,6 +9,7 @@ import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.cryptomator.common.AutoClosingStream;
|
||||
import org.cryptomator.common.WeakValuedCache;
|
||||
import org.cryptomator.filesystem.File;
|
||||
import org.cryptomator.filesystem.Folder;
|
||||
@@ -27,7 +28,7 @@ class NioFolder extends NioNode implements Folder {
|
||||
@Override
|
||||
public Stream<? extends Node> children() throws UncheckedIOException {
|
||||
try {
|
||||
return nioAccess.list(path).map(this::childPathToNode);
|
||||
return AutoClosingStream.from(nioAccess.list(path).map(this::childPathToNode));
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
}
|
||||
@@ -130,6 +131,7 @@ class NioFolder extends NioNode implements Folder {
|
||||
if (!exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
folders().forEach(Folder::delete);
|
||||
files().forEach(NioFolder::deleteFile);
|
||||
try {
|
||||
|
||||
@@ -5,6 +5,7 @@ import static java.util.stream.Collectors.toList;
|
||||
import static org.cryptomator.common.test.matcher.ContainsMatcher.contains;
|
||||
import static org.cryptomator.filesystem.nio.ReflectiveClassMatchers.aClassThatDoesDeclareMethod;
|
||||
import static org.cryptomator.filesystem.nio.ReflectiveClassMatchers.aClassThatDoesNotDeclareMethod;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.theInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -23,6 +24,7 @@ import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.cryptomator.common.AutoClosingStream;
|
||||
import org.cryptomator.filesystem.File;
|
||||
import org.cryptomator.filesystem.FileSystem;
|
||||
import org.cryptomator.filesystem.Folder;
|
||||
@@ -75,6 +77,14 @@ public class NioFolderTest {
|
||||
|
||||
public class ChildrenTests {
|
||||
|
||||
@Test
|
||||
public void testChildrenReturnsAnAutoClosingStream() throws IOException {
|
||||
Stream<Path> childrenPaths = Stream.<Path>builder().build();
|
||||
when(nioAccess.list(path)).thenReturn(childrenPaths);
|
||||
|
||||
assertThat(inTest.children(), is(instanceOf(AutoClosingStream.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChildrenConvertsPathWhichIsADirectoryToAnNioFolderUsingTheInstanceFactory() throws IOException {
|
||||
Path childFolderPath = mock(Path.class);
|
||||
|
||||
Reference in New Issue
Block a user