本文整理了Java中org.assertj.core.api.AbstractPathAssert.isDirectory()
方法的一些代码示例,展示了AbstractPathAssert.isDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractPathAssert.isDirectory()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractPathAssert
类名称:AbstractPathAssert
方法名:isDirectory
[英]Assert that the tested Path is a directory.
Note that this method will follow symbolic links. If you are a Unix user and wish to assert that a path is a symbolic link instead, use #isSymbolicLink().
This assertion first asserts the existence of the path (using #exists()) then checks whether the path is a directory.
Examples:
// fs is a Unix filesystem
// Create a regular file, and a symbolic link to that regular file
final Path existingFile = fs.getPath("existingFile");
final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");
Files.createFile(existingFile);
Files.createSymbolicLink(symlinkToExistingFile, existingFile);
// Create a directory, and a symbolic link to that directory
final Path dir = fs.getPath("dir");
final Path dirSymlink = fs.getPath("dirSymlink");
Files.createDirectories(dir);
Files.createSymbolicLink(dirSymlink, dir);
// Create a nonexistent entry, and a symbolic link to that entry
final Path nonExistentPath = fs.getPath("nonexistent");
final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");
Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);
// the following assertions succeed:
assertThat(dir).isDirectory();
assertThat(dirSymlink).isDirectory();
// the following assertions fail because paths do not exist:
assertThat(nonExistentPath).isDirectory();
assertThat(symlinkToNonExistentPath).isDirectory();
// the following assertions fail because paths exist but are not directories:
assertThat(existingFile).isDirectory();
assertThat(symlinkToExistingFile).isDirectory();
[中]断言测试路径是一个目录。
请注意,此方法将遵循符号链接。如果您是Unix用户,并且希望声明路径是符号链接,请使用#isSymbolicLink()。
此断言首先断言路径的存在(使用#exists()),然后检查路径是否为目录。
示例:
// fs is a Unix filesystem
// Create a regular file, and a symbolic link to that regular file
final Path existingFile = fs.getPath("existingFile");
final Path symlinkToExistingFile = fs.getPath("symlinkToExistingFile");
Files.createFile(existingFile);
Files.createSymbolicLink(symlinkToExistingFile, existingFile);
// Create a directory, and a symbolic link to that directory
final Path dir = fs.getPath("dir");
final Path dirSymlink = fs.getPath("dirSymlink");
Files.createDirectories(dir);
Files.createSymbolicLink(dirSymlink, dir);
// Create a nonexistent entry, and a symbolic link to that entry
final Path nonExistentPath = fs.getPath("nonexistent");
final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath");
Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath);
// the following assertions succeed:
assertThat(dir).isDirectory();
assertThat(dirSymlink).isDirectory();
// the following assertions fail because paths do not exist:
assertThat(nonExistentPath).isDirectory();
assertThat(symlinkToNonExistentPath).isDirectory();
// the following assertions fail because paths exist but are not directories:
assertThat(existingFile).isDirectory();
assertThat(symlinkToExistingFile).isDirectory();
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldGenerateAttachments() throws Exception {
final Path attachmentsFolder = output.resolve("data/attachments");
assertThat(attachmentsFolder)
.isDirectory();
assertThat(Files.list(attachmentsFolder))
.hasSize(13);
}
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldGenerateTestCases() throws Exception {
final Path testCasesFolder = output.resolve("data/test-cases");
assertThat(testCasesFolder)
.isDirectory();
assertThat(Files.list(testCasesFolder))
.hasSize(20);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteQuietly_deletes_directory_and_content() throws IOException {
Path target = temporaryFolder.newFolder().toPath();
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
FileUtils.deleteQuietly(target.toFile());
assertThat(target).doesNotExist();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteDirectory_deletes_directory_and_content() throws IOException {
Path target = temporaryFolder.newFolder().toPath();
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
FileUtils.deleteQuietly(target.toFile());
assertThat(target).doesNotExist();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_not_delete_report_if_property_is_set() throws IOException {
when(properties.shouldKeepReport()).thenReturn(true);
Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
Files.createDirectory(reportDir);
underTest.start();
underTest.stop();
assertThat(reportDir).isDirectory();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteDirectory_deletes_directory_and_content() throws IOException {
Path target = temporaryFolder.newFolder().toPath();
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
FileUtils2.deleteQuietly(target.toFile());
assertThat(target).doesNotExist();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteQuietly_deletes_directory_and_content() throws IOException {
Path target = temporaryFolder.newFolder().toPath();
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
FileUtils2.deleteQuietly(target.toFile());
assertThat(target).doesNotExist();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void cleanDirectory_removes_directories_and_files_in_target_directory_but_not_target_directory() throws IOException {
Path target = temporaryFolder.newFolder().toPath();
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
// on supporting FileSystem, target will change if directory is recreated
Object targetKey = getFileKey(target);
FileUtils.cleanDirectory(target.toFile());
assertThat(target).isDirectory();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
assertThat(getFileKey(target)).isEqualTo(targetKey);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void cleanDirectory_removes_directories_and_files_in_target_directory_but_not_target_directory() throws IOException {
Path target = temporaryFolder.newFolder().toPath();
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
// on supporting FileSystem, target will change if directory is recreated
Object targetKey = getFileKey(target);
FileUtils2.cleanDirectory(target.toFile());
assertThat(target).isDirectory();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
assertThat(getFileKey(target)).isEqualTo(targetKey);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void cleanDirectory_follows_symlink_to_target_directory() throws IOException {
assumeTrue(SystemUtils.IS_OS_UNIX);
Path target = temporaryFolder.newFolder().toPath();
Path symToDir = Files.createSymbolicLink(temporaryFolder.newFolder().toPath().resolve("sym_to_dir"), target);
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(symToDir).isSymbolicLink();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
// on supporting FileSystem, target will change if directory is recreated
Object targetKey = getFileKey(target);
Object symLinkKey = getFileKey(symToDir);
FileUtils.cleanDirectory(symToDir.toFile());
assertThat(target).isDirectory();
assertThat(symToDir).isSymbolicLink();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
assertThat(getFileKey(target)).isEqualTo(targetKey);
assertThat(getFileKey(symToDir)).isEqualTo(symLinkKey);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void cleanDirectory_follows_symlink_to_target_directory() throws IOException {
assumeTrue(SystemUtils.IS_OS_UNIX);
Path target = temporaryFolder.newFolder().toPath();
Path symToDir = Files.createSymbolicLink(temporaryFolder.newFolder().toPath().resolve("sym_to_dir"), target);
Path childFile1 = Files.createFile(target.resolve("file1.txt"));
Path childDir1 = Files.createDirectory(target.resolve("subDir1"));
Path childFile2 = Files.createFile(childDir1.resolve("file2.txt"));
Path childDir2 = Files.createDirectory(childDir1.resolve("subDir2"));
assertThat(target).isDirectory();
assertThat(symToDir).isSymbolicLink();
assertThat(childFile1).isRegularFile();
assertThat(childDir1).isDirectory();
assertThat(childFile2).isRegularFile();
assertThat(childDir2).isDirectory();
// on supporting FileSystem, target will change if directory is recreated
Object targetKey = getFileKey(target);
Object symLinkKey = getFileKey(symToDir);
FileUtils2.cleanDirectory(symToDir.toFile());
assertThat(target).isDirectory();
assertThat(symToDir).isSymbolicLink();
assertThat(childFile1).doesNotExist();
assertThat(childDir1).doesNotExist();
assertThat(childFile2).doesNotExist();
assertThat(childDir2).doesNotExist();
assertThat(getFileKey(target)).isEqualTo(targetKey);
assertThat(getFileKey(symToDir)).isEqualTo(symLinkKey);
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
public void testRootisADir() throws IOException {
assertThat( defaultRoot() ).isDirectory();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
public void testDefaultIsDir() throws Exception {
assertThat( pathDefault() ).isDirectory();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SymLink.class } )
public void testSymLinkChanges() throws IOException {
Path target = targetFile();
Files.createSymbolicLink( symLink(), target );
Files.delete( target );
Files.createDirectory( target );
assertThat( symLink() ).isDirectory();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { Writable.class, Move.class } )
public void testMoveEmptyDir() throws IOException {
Files.move( srcDir(), tgt() );
assertThat( tgt() ).isDirectory();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { Writable.class, Copy.class } )
public void testCopyDirReplaceExistingOverwritesFile() throws Exception {
// that's a surprise, todo bugs ?
Files.write( tgt(), CONTENT, standardOpen );
Files.copy( srcDir(), tgt(), StandardCopyOption.REPLACE_EXISTING );
assertThat( tgt() ).isDirectory();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SymLink.class, DirSymLink.class } )
public void testCreateDirInDirSymLink() throws IOException {
Files.createSymbolicLink( symLink(), targetDir() );
Files.createDirectory( linkKid() );
assertThat( linkKid() ).isDirectory();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SymLink.class, DirSymLink.class } )
public void testDirSymLink() throws IOException {
Files.createSymbolicLink( symLink(), targetDir() );
assertThat( symLink() ).isDirectory();
}
内容来源于网络,如有侵权,请联系作者删除!