use of java.nio.file.NotDirectoryException in project j2objc by google.
the class Files2Test method test_list.
@Test
public void test_list() throws Exception {
// Directory Setup for the test.
Path rootDir = Paths.get(filesSetup.getTestDir(), "root");
Path dir1 = Paths.get(filesSetup.getTestDir(), "root/dir1");
Path file1 = Paths.get(filesSetup.getTestDir(), "root/file1");
Path file2 = Paths.get(filesSetup.getTestDir(), "root/dir1/file2");
Path symLink = Paths.get(filesSetup.getTestDir(), "root/symlink");
Files.createDirectories(dir1);
Files.createFile(file1);
Files.createFile(file2);
Files.createSymbolicLink(symLink, file1.toAbsolutePath());
Set<Path> expectedVisitedFiles = new HashSet<>();
expectedVisitedFiles.add(dir1);
expectedVisitedFiles.add(file1);
expectedVisitedFiles.add(symLink);
Set<Path> visitedFiles = new HashSet<>();
try (Stream<Path> pathStream = Files.list(rootDir)) {
pathStream.forEach(path -> visitedFiles.add(path));
}
assertEquals(3, visitedFiles.size());
// Test the case where directory is empty.
filesSetup.clearAll();
try {
Files.list(Paths.get(filesSetup.getTestDir(), "newDir"));
fail();
} catch (NoSuchFileException expected) {
}
// Test the case where path points to a file.
filesSetup.clearAll();
filesSetup.setUp();
try {
Files.list(filesSetup.getDataFilePath());
fail();
} catch (NotDirectoryException expected) {
}
}
use of java.nio.file.NotDirectoryException in project j2objc by google.
the class NotDirectoryExceptionTest method test_constructor$String.
public void test_constructor$String() {
NotDirectoryException exception = new NotDirectoryException("file");
assertEquals("file", exception.getFile());
assertNull(exception.getOtherFile());
assertNull(exception.getReason());
assertTrue(exception instanceof FileSystemException);
}
use of java.nio.file.NotDirectoryException in project j2objc by google.
the class DefaultFileSystemProviderTest method test_newDirectoryStream$Filter_Exception.
/**
* Tests exceptions for the newDirectoryStream(Path, DirectoryStream.Filter) method
* - NoSuchFileException & NoDirectoryException.
* @throws IOException
*/
@Test
public void test_newDirectoryStream$Filter_Exception() throws IOException {
// Non existent directory.
Path path_dir1 = filesSetup.getPathInTestDir("newDir1");
DirectoryStream.Filter<Path> fileFilter = new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
return Files.isDirectory(entry);
}
};
try (DirectoryStream<Path> directoryStream = provider.newDirectoryStream(path_dir1, fileFilter)) {
fail();
} catch (NoSuchFileException expected) {
assertTrue(expected.getMessage().contains(path_dir1.toString()));
}
// File instead of directory.
Path path_file1 = filesSetup.getPathInTestDir("newFile1");
Files.createFile(path_file1);
try (DirectoryStream<Path> directoryStream = provider.newDirectoryStream(path_file1, fileFilter)) {
fail();
} catch (NotDirectoryException expected) {
}
}
use of java.nio.file.NotDirectoryException in project j2objc by google.
the class FilesTest method test_newDirectoryStream_Exception.
@Test
public void test_newDirectoryStream_Exception() throws IOException {
// Non existent directory.
Path path_dir1 = filesSetup.getPathInTestDir("newDir1");
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_dir1)) {
fail();
} catch (NoSuchFileException expected) {
}
// File instead of directory.
Path path_file1 = filesSetup.getPathInTestDir("newFile1");
Files.createFile(path_file1);
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_file1)) {
fail();
} catch (NotDirectoryException expected) {
}
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(null)) {
fail();
} catch (NullPointerException expected) {
}
}
use of java.nio.file.NotDirectoryException in project j2objc by google.
the class FilesTest method test_newDirectoryStream$Path$String_Exception.
@Test
public void test_newDirectoryStream$Path$String_Exception() throws IOException {
// Non existent directory.
Path path_dir1 = filesSetup.getPathInTestDir("newDir1");
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_dir1, "*.c")) {
fail();
} catch (NoSuchFileException expected) {
}
// File instead of directory.
Path path_file1 = filesSetup.getPathInTestDir("newFile1");
Files.createFile(path_file1);
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_file1, "*.c")) {
fail();
} catch (NotDirectoryException expected) {
}
Files.createFile(path_dir1);
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_file1, "[a")) {
fail();
} catch (PatternSyntaxException expected) {
}
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(null, "[a")) {
fail();
} catch (NullPointerException expected) {
}
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(path_dir1, (String) null)) {
fail();
} catch (NullPointerException expected) {
}
}
Aggregations