diff --git a/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderChildrenTests.java b/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderChildrenTests.java index 463976e52..843fc87e7 100644 --- a/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderChildrenTests.java +++ b/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderChildrenTests.java @@ -13,7 +13,7 @@ import java.io.UncheckedIOException; import org.cryptomator.filesystem.FileSystem; import org.cryptomator.filesystem.Folder; import org.cryptomator.filesystem.invariants.FileSystemFactories.FileSystemFactory; -import org.cryptomator.filesystem.invariants.SubfolderFactories.SubfolderFactory; +import org.cryptomator.filesystem.invariants.SubfolderBiFunctions.SubfolderBiFunction; import org.junit.Rule; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; @@ -30,17 +30,17 @@ public class FolderChildrenTests { public static final Iterable FILE_SYSTEM_FACTORIES = new FileSystemFactories(); @DataPoints - public static final Iterable SUBFOLDER_FACTORIES = new SubfolderFactories(); + public static final Iterable SUBFOLDER_BI_FUNCTIONS = new SubfolderBiFunctions(); @Rule public final ExpectedException thrown = ExpectedException.none(); @Theory - public void testChildrenThrowsExceptionIfFolderDoesNotExist(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(false)); + public void testChildrenThrowsExceptionIfFolderDoesNotExist(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFunction) { + assumeThat(subfolderFunction.returnedFoldersExist(), is(false)); FileSystem fileSystem = fileSystemFactory.create(); - Folder nonExistingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); + Folder nonExistingFolder = subfolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); thrown.expect(UncheckedIOException.class); @@ -48,11 +48,11 @@ public class FolderChildrenTests { } @Theory - public void testFilesThrowsExceptionIfFolderDoesNotExist(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(false)); + public void testFilesThrowsExceptionIfFolderDoesNotExist(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFunction) { + assumeThat(subfolderFunction.returnedFoldersExist(), is(false)); FileSystem fileSystem = fileSystemFactory.create(); - Folder nonExistingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); + Folder nonExistingFolder = subfolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); thrown.expect(UncheckedIOException.class); @@ -60,11 +60,11 @@ public class FolderChildrenTests { } @Theory - public void testFoldersThrowsExceptionIfFolderDoesNotExist(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(false)); + public void testFoldersThrowsExceptionIfFolderDoesNotExist(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFunction) { + assumeThat(subfolderFunction.returnedFoldersExist(), is(false)); FileSystem fileSystem = fileSystemFactory.create(); - Folder nonExistingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); + Folder nonExistingFolder = subfolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); thrown.expect(UncheckedIOException.class); @@ -72,62 +72,93 @@ public class FolderChildrenTests { } @Theory - public void testChildrenIsEmptyForEmptyFolder(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(true)); + public void testChildrenIsEmptyForEmptyFolder(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFunction) { + assumeThat(subfolderFunction.returnedFoldersExist(), is(true)); FileSystem fileSystem = fileSystemFactory.create(); - Folder existingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); + Folder existingFolder = subfolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); assertThat(existingFolder.children().count(), is(0L)); } @Theory - public void testFilesIsEmptyForEmptyFolder(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(true)); + public void testFilesIsEmptyForEmptyFolder(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFunction) { + assumeThat(subfolderFunction.returnedFoldersExist(), is(true)); FileSystem fileSystem = fileSystemFactory.create(); - Folder existingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); + Folder existingFolder = subfolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); assertThat(existingFolder.files().count(), is(0L)); } @Theory - public void testFoldersIsEmptyForEmptyFolder(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(true)); + public void testFoldersIsEmptyForEmptyFolder(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFunction) { + assumeThat(subfolderFunction.returnedFoldersExist(), is(true)); FileSystem fileSystem = fileSystemFactory.create(); - Folder existingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); + Folder existingFolder = subfolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); assertThat(existingFolder.folders().count(), is(0L)); } @Theory - public void testChildrenContainsCreatedChildFolder(FileSystemFactory fileSystemFactory, SubfolderFactory existingFolderFactory, SubfolderFactory childExistingFolderFactory) { - assumeThat(existingFolderFactory.createsExistingFolder(), is(true)); - assumeThat(childExistingFolderFactory.createsExistingFolder(), is(true)); + public void testChildrenContainsCreatedChildFolder(FileSystemFactory fileSystemFactory, SubfolderBiFunction existingFolderFunction, SubfolderBiFunction childExistingFolderFunction) { + assumeThat(existingFolderFunction.returnedFoldersExist(), is(true)); + assumeThat(childExistingFolderFunction.returnedFoldersExist(), is(true)); String childName = "childFolderName"; FileSystem fileSystem = fileSystemFactory.create(); - Folder existingFolder = existingFolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); - Folder childFolder = childExistingFolderFactory.subfolderWithName(existingFolder, childName); + Folder existingFolder = existingFolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); + Folder childFolder = childExistingFolderFunction.subfolderWithName(existingFolder, childName); assertThat(existingFolder.children().collect(toList()), containsInAnyOrder(equalTo(childFolder))); } @Theory - public void testChildrenDoesNotContainsCreatedAndDeletedChildFolder(FileSystemFactory fileSystemFactory, SubfolderFactory existingFolderFactory, SubfolderFactory childExistingFolderFactory) { - assumeThat(existingFolderFactory.createsExistingFolder(), is(true)); - assumeThat(childExistingFolderFactory.createsExistingFolder(), is(true)); + public void testChildrenDoesNotContainCreatedAndDeletedChildFolder(FileSystemFactory fileSystemFactory, SubfolderBiFunction existingFolderFunction, SubfolderBiFunction childExistingFolderFunction) { + assumeThat(existingFolderFunction.returnedFoldersExist(), is(true)); + assumeThat(childExistingFolderFunction.returnedFoldersExist(), is(true)); String childName = "childFolderName"; FileSystem fileSystem = fileSystemFactory.create(); - Folder existingFolder = existingFolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); - Folder childFolder = childExistingFolderFactory.subfolderWithName(existingFolder, childName); + Folder existingFolder = existingFolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); + Folder childFolder = childExistingFolderFunction.subfolderWithName(existingFolder, childName); childFolder.delete(); assertThat(existingFolder.children().collect(toList()), is(empty())); } + @Theory + public void testFoldersContainsAndFilesDoesNotContainCreatedChildFolder(FileSystemFactory fileSystemFactory, SubfolderBiFunction existingFolderFunction, SubfolderBiFunction childExistingFolderFunction) { + assumeThat(existingFolderFunction.returnedFoldersExist(), is(true)); + assumeThat(childExistingFolderFunction.returnedFoldersExist(), is(true)); + + String childName = "childFolderName"; + + FileSystem fileSystem = fileSystemFactory.create(); + Folder existingFolder = existingFolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); + Folder childFolder = childExistingFolderFunction.subfolderWithName(existingFolder, childName); + + assertThat(existingFolder.folders().collect(toList()), containsInAnyOrder(equalTo(childFolder))); + assertThat(existingFolder.files().collect(toList()), is(empty())); + } + + @Theory + public void testFoldersAndFilesDoesNotContainCreatedAndDeletedChildFolder(FileSystemFactory fileSystemFactory, SubfolderBiFunction existingFolderFunction, SubfolderBiFunction childExistingFolderFunction) { + assumeThat(existingFolderFunction.returnedFoldersExist(), is(true)); + assumeThat(childExistingFolderFunction.returnedFoldersExist(), is(true)); + + String childName = "childFolderName"; + + FileSystem fileSystem = fileSystemFactory.create(); + Folder existingFolder = existingFolderFunction.subfolderWithName(fileSystem, FOLDER_NAME); + Folder childFolder = childExistingFolderFunction.subfolderWithName(existingFolder, childName); + childFolder.delete(); + + assertThat(existingFolder.folders().collect(toList()), is(empty())); + assertThat(existingFolder.files().collect(toList()), is(empty())); + } + } diff --git a/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderTests.java b/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderTests.java index 0a748e362..77fd5bb93 100644 --- a/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderTests.java +++ b/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/FolderTests.java @@ -7,7 +7,7 @@ import static org.junit.Assume.assumeThat; import org.cryptomator.filesystem.FileSystem; import org.cryptomator.filesystem.Folder; import org.cryptomator.filesystem.invariants.FileSystemFactories.FileSystemFactory; -import org.cryptomator.filesystem.invariants.SubfolderFactories.SubfolderFactory; +import org.cryptomator.filesystem.invariants.SubfolderBiFunctions.SubfolderBiFunction; import org.junit.Rule; import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; @@ -24,14 +24,14 @@ public class FolderTests { public static final Iterable FILE_SYSTEM_FACTORIES = new FileSystemFactories(); @DataPoints - public static final Iterable SUBFOLDER_FACTORIES = new SubfolderFactories(); + public static final Iterable SUBFOLDER_FACTORIES = new SubfolderBiFunctions(); @Rule public final ExpectedException thrown = ExpectedException.none(); @Theory - public void testExistingFolderExists(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(true)); + public void testExistingFolderExists(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFactory) { + assumeThat(subfolderFactory.returnedFoldersExist(), is(true)); FileSystem fileSystem = fileSystemFactory.create(); Folder existingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); @@ -40,8 +40,8 @@ public class FolderTests { } @Theory - public void testNonExistingFolderDoesntExists(FileSystemFactory fileSystemFactory, SubfolderFactory subfolderFactory) { - assumeThat(subfolderFactory.createsExistingFolder(), is(false)); + public void testNonExistingFolderDoesntExists(FileSystemFactory fileSystemFactory, SubfolderBiFunction subfolderFactory) { + assumeThat(subfolderFactory.returnedFoldersExist(), is(false)); FileSystem fileSystem = fileSystemFactory.create(); Folder existingFolder = subfolderFactory.subfolderWithName(fileSystem, FOLDER_NAME); diff --git a/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/SubfolderFactories.java b/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/SubfolderBiFunctions.java similarity index 68% rename from main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/SubfolderFactories.java rename to main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/SubfolderBiFunctions.java index 00bff41df..5c12b4fcc 100644 --- a/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/SubfolderFactories.java +++ b/main/filesystem-invariants-tests/src/test/java/org/cryptomator/filesystem/invariants/SubfolderBiFunctions.java @@ -5,13 +5,13 @@ import java.util.Iterator; import java.util.List; import org.cryptomator.filesystem.Folder; -import org.cryptomator.filesystem.invariants.SubfolderFactories.SubfolderFactory; +import org.cryptomator.filesystem.invariants.SubfolderBiFunctions.SubfolderBiFunction; -class SubfolderFactories implements Iterable { +class SubfolderBiFunctions implements Iterable { - private final List factories = new ArrayList<>(); + private final List factories = new ArrayList<>(); - public SubfolderFactories() { + public SubfolderBiFunctions() { addNonExisting("invoke folder", this::invokeFolder); addNonExisting("create and delete", this::createAndDeleteFolder); addNonExisting("delete by moving", this::moveFolderAway); @@ -54,8 +54,8 @@ class SubfolderFactories implements Iterable { return target; } - private void addExisting(String name, ExistingSubfolderFactory factory) { - factories.add(new ExistingSubfolderFactory() { + private void addExisting(String name, ExistingSubfolderBiFunction factory) { + factories.add(new ExistingSubfolderBiFunction() { @Override public Folder subfolderWithName(Folder parent, String name) { return factory.subfolderWithName(parent, name); @@ -68,8 +68,8 @@ class SubfolderFactories implements Iterable { }); } - private void addNonExisting(String name, NonExistingSubfolderFactory factory) { - factories.add(new NonExistingSubfolderFactory() { + private void addNonExisting(String name, NonExistingSubfolderSubfolderBiFunction factory) { + factories.add(new NonExistingSubfolderSubfolderBiFunction() { @Override public Folder subfolderWithName(Folder parent, String name) { return factory.subfolderWithName(parent, name); @@ -82,30 +82,30 @@ class SubfolderFactories implements Iterable { }); } - public interface SubfolderFactory { + public interface SubfolderBiFunction { Folder subfolderWithName(Folder parent, String name); - boolean createsExistingFolder(); + boolean returnedFoldersExist(); } - public interface ExistingSubfolderFactory extends SubfolderFactory { + public interface ExistingSubfolderBiFunction extends SubfolderBiFunction { @Override - default boolean createsExistingFolder() { + default boolean returnedFoldersExist() { return true; } } - public interface NonExistingSubfolderFactory extends SubfolderFactory { + public interface NonExistingSubfolderSubfolderBiFunction extends SubfolderBiFunction { @Override - default boolean createsExistingFolder() { + default boolean returnedFoldersExist() { return false; } } @Override - public Iterator iterator() { + public Iterator iterator() { return factories.iterator(); }