本文整理了Java中org.assertj.core.api.AbstractPathAssert.isSymbolicLink()
方法的一些代码示例,展示了AbstractPathAssert.isSymbolicLink()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractPathAssert.isSymbolicLink()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractPathAssert
类名称:AbstractPathAssert
方法名:isSymbolicLink
[英]Assert that the tested Path is a symbolic link.
This assertion first asserts the existence of the path (using #existsNoFollowLinks()) then checks whether the path is a symbolic link.
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(dirSymlink).isSymbolicLink();
assertThat(symlinkToExistingFile).isSymbolicLink();
assertThat(symlinkToNonExistentPath).isSymbolicLink();
// the following assertion fails because the path does not exist:
assertThat(nonExistentPath).isSymbolicLink();
// the following assertions fail because paths exist but are not symbolic links
assertThat(existingFile).isSymbolicLink();
assertThat(dir).isSymbolicLink();
[中]断言测试路径是符号链接。
此断言首先断言路径的存在(使用#existsnoflowlinks()),然后检查路径是否为符号链接。
示例:
// 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(dirSymlink).isSymbolicLink();
assertThat(symlinkToExistingFile).isSymbolicLink();
assertThat(symlinkToNonExistentPath).isSymbolicLink();
// the following assertion fails because the path does not exist:
assertThat(nonExistentPath).isSymbolicLink();
// the following assertions fail because paths exist but are not symbolic links
assertThat(existingFile).isSymbolicLink();
assertThat(dir).isSymbolicLink();
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteDirectory_throws_IOE_if_file_is_symbolicLink() throws IOException {
assumeTrue(SystemUtils.IS_OS_UNIX);
Path folder = temporaryFolder.newFolder().toPath();
Path file1 = Files.createFile(folder.resolve("file1.txt"));
Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1);
assertThat(file1).isRegularFile();
assertThat(symLink).isSymbolicLink();
expectedException.expect(IOException.class);
expectedException.expectMessage("Directory '" + symLink.toFile().getAbsolutePath() + "' is a symbolic link");
FileUtils.deleteDirectory(symLink.toFile());
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteQuietly_deletes_symbolicLink() throws IOException {
assumeTrue(SystemUtils.IS_OS_UNIX);
Path folder = temporaryFolder.newFolder().toPath();
Path file1 = Files.createFile(folder.resolve("file1.txt"));
Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1);
assertThat(file1).isRegularFile();
assertThat(symLink).isSymbolicLink();
FileUtils.deleteQuietly(symLink.toFile());
assertThat(symLink).doesNotExist();
assertThat(file1).isRegularFile();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteQuietly_deletes_symbolicLink() throws IOException {
assumeTrue(SystemUtils.IS_OS_UNIX);
Path folder = temporaryFolder.newFolder().toPath();
Path file1 = Files.createFile(folder.resolve("file1.txt"));
Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1);
assertThat(file1).isRegularFile();
assertThat(symLink).isSymbolicLink();
FileUtils2.deleteQuietly(symLink.toFile());
assertThat(symLink).doesNotExist();
assertThat(file1).isRegularFile();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void deleteDirectory_throws_IOE_if_file_is_symbolicLink() throws IOException {
assumeTrue(SystemUtils.IS_OS_UNIX);
Path folder = temporaryFolder.newFolder().toPath();
Path file1 = Files.createFile(folder.resolve("file1.txt"));
Path symLink = Files.createSymbolicLink(folder.resolve("link1"), file1);
assertThat(file1).isRegularFile();
assertThat(symLink).isSymbolicLink();
expectedException.expect(IOException.class);
expectedException.expectMessage("Directory '" + symLink.toFile().getAbsolutePath() + "' is a symbolic link");
FileUtils2.deleteDirectory(symLink.toFile());
}
代码示例来源: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
@Category( { SymLink.class, DirSymLink.class } )
public void testGetDirStreamFromDirSymLink() throws IOException {
Files.createSymbolicLink( symLink(), targetDir() );
try( DirectoryStream<Path> stream = Files.newDirectoryStream( symLink() ) ) {
for( Path kid : stream ) {
assertThat( kid.getParent() ).isSymbolicLink();
assertThat( Files.isSameFile( kid, targetDirKid() ) ).isTrue();
}
}
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SymLink.class } )
public void testBrokenSymLinkThrowsOnIsSymlink() throws IOException {
Files.createSymbolicLink( symLink(), absTA() );
assertThat( symLink() ).isSymbolicLink();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SymLink.class } )
public void testSymLinkAttributeLink() throws IOException {
Files.createSymbolicLink( symLink(), targetDir() );
assertThat( symLink() ).isSymbolicLink();
}
代码示例来源:origin: de.pfabulist.lindwurm/niotest
@Test
@Category( { SymLink.class, Writable.class, Move.class } )
public void testMoveSymLinkFileKeepsSymLinkStatus() throws IOException {
Files.createSymbolicLink( symLink(), targetFile() );
Files.move( symLink(), tgt() );
assertThat( tgt() ).isSymbolicLink();
}
内容来源于网络,如有侵权,请联系作者删除!