|
@@ -18,12 +18,19 @@ import org.junit.Test;
|
|
|
public class BlacklistingFileSystemTest {
|
|
|
|
|
|
@Test(expected = UncheckedIOException.class)
|
|
|
- public void testPreventCreationOfMetadataFolder() {
|
|
|
+ public void testPreventCreationOfBlacklistedFolder() {
|
|
|
final FileSystem underlyingFs = new InMemoryFileSystem();
|
|
|
- final Folder metadataRoot = underlyingFs.folder("m");
|
|
|
- final Predicate<Node> metadataHidden = (Node n) -> n.equals(metadataRoot);
|
|
|
- final FileSystem fs = new BlacklistingFileSystem(underlyingFs, metadataHidden);
|
|
|
- fs.folder("m");
|
|
|
+ final Node blacklisted = underlyingFs.folder("qwe");
|
|
|
+ final FileSystem fs = new BlacklistingFileSystem(underlyingFs, SamePathPredicate.forNode(blacklisted));
|
|
|
+ fs.folder("qwe");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test(expected = UncheckedIOException.class)
|
|
|
+ public void testPreventCreationOBlacklistedFile() {
|
|
|
+ final FileSystem underlyingFs = new InMemoryFileSystem();
|
|
|
+ final Node blacklisted = underlyingFs.folder("qwe");
|
|
|
+ final FileSystem fs = new BlacklistingFileSystem(underlyingFs, SamePathPredicate.forNode(blacklisted));
|
|
|
+ fs.file("qwe");
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -33,8 +40,8 @@ public class BlacklistingFileSystemTest {
|
|
|
final File hiddenFile = underlyingFs.file("qwe");
|
|
|
final Folder visibleFolder = underlyingFs.folder("sdf");
|
|
|
final File visibleFile = underlyingFs.file("wer");
|
|
|
- final Predicate<Node> metadataHidden = (Node n) -> n.equals(hiddenFolder) || n.equals(hiddenFile);
|
|
|
- final FileSystem fs = new BlacklistingFileSystem(underlyingFs, metadataHidden);
|
|
|
+ final Predicate<Node> hiddenPredicate = SamePathPredicate.forNode(hiddenFolder).or(SamePathPredicate.forNode(hiddenFile));
|
|
|
+ final FileSystem fs = new BlacklistingFileSystem(underlyingFs, hiddenPredicate);
|
|
|
hiddenFolder.create();
|
|
|
try (WritableByteChannel writable = hiddenFile.openWritable()) {
|
|
|
writable.write(ByteBuffer.allocate(0));
|
|
@@ -46,6 +53,7 @@ public class BlacklistingFileSystemTest {
|
|
|
|
|
|
Assert.assertArrayEquals(new String[] {"sdf"}, fs.folders().map(Node::name).collect(Collectors.toList()).toArray());
|
|
|
Assert.assertArrayEquals(new String[] {"wer"}, fs.files().map(Node::name).collect(Collectors.toList()).toArray());
|
|
|
+ Assert.assertArrayEquals(new String[] {"sdf", "wer"}, fs.children().map(Node::name).sorted().collect(Collectors.toList()).toArray());
|
|
|
}
|
|
|
|
|
|
}
|