org.assertj.core.api.AbstractPathAssert.existsNoFollowLinks()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(60)

本文整理了Java中org.assertj.core.api.AbstractPathAssert.existsNoFollowLinks()方法的一些代码示例,展示了AbstractPathAssert.existsNoFollowLinks()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractPathAssert.existsNoFollowLinks()方法的具体详情如下:
包路径:org.assertj.core.api.AbstractPathAssert
类名称:AbstractPathAssert
方法名:existsNoFollowLinks

AbstractPathAssert.existsNoFollowLinks介绍

[英]Assert that the tested Path exists, not following symbolic links, by calling Files#exists(Path,LinkOption...)).

This assertion behaves like #exists(), with the difference that it can be used to assert the existence of a symbolic link even if its target is invalid.

Examples:

// fs is a Unix filesystem 
// Create a regular file, and a symbolic link pointing to it 
final Path existingFile = fs.getPath("somefile"); 
Files.createFile(existingFile); 
final Path symlinkToExistingFile = fs.getPath("symlink"); 
Files.createSymbolicLink(symlinkToExistingFile, existingFile); 
// Create a symbolic link whose target does not exist 
final Path nonExistentPath = fs.getPath("nonexistent"); 
final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath"); 
Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath); 
// The following assertions succeed 
assertThat(existingFile).existsNoFollowLinks(); 
assertThat(symlinkToExistingFile).existsNoFollowLinks(); 
assertThat(symlinkToNonExistentPath).existsNoFollowLinks(); 
// The following assertion fails 
assertThat(nonExistentPath).existsNoFollowLinks();

[中]通过调用文件#exists(Path,LinkOption…),断言测试路径存在,而不是遵循符号链接。
此断言的行为类似于#exists(),区别在于它可以用于断言符号链接的存在,即使其目标无效。
示例:

// fs is a Unix filesystem 
// Create a regular file, and a symbolic link pointing to it 
final Path existingFile = fs.getPath("somefile"); 
Files.createFile(existingFile); 
final Path symlinkToExistingFile = fs.getPath("symlink"); 
Files.createSymbolicLink(symlinkToExistingFile, existingFile); 
// Create a symbolic link whose target does not exist 
final Path nonExistentPath = fs.getPath("nonexistent"); 
final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath"); 
Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath); 
// The following assertions succeed 
assertThat(existingFile).existsNoFollowLinks(); 
assertThat(symlinkToExistingFile).existsNoFollowLinks(); 
assertThat(symlinkToNonExistentPath).existsNoFollowLinks(); 
// The following assertion fails 
assertThat(nonExistentPath).existsNoFollowLinks();

代码示例

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test
@Category( { SymLink.class, Writable.class } )
public void testMoveLinkToNonExistingPath() throws IOException {
  Files.createSymbolicLink( symLink(), absAB() );
  Path to = dirTB().resolve( nameB() );
  Files.move( symLink(), to );
  assertThat( to ).existsNoFollowLinks();
}

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test
@Category( { SymLink.class, Writable.class } )
public void testCreateSymLinkToNonExisting() throws IOException {
  Files.createSymbolicLink( link(), absTA() );
  assertThat( link() ).existsNoFollowLinks();
}

代码示例来源:origin: de.pfabulist.lindwurm/niotest

@Test
@Category( { SymLink.class } )
public void testBrokenSymLinkNoFollowLinkExists() throws IOException {
  Files.createSymbolicLink( symLink(), absTA() );
  assertThat( symLink() ).existsNoFollowLinks();
}

代码示例来源:origin: line/centraldogma

/**
 * Makes sure {@link GitRepository} can create the legacy format repository, with Git repository format
 * version 0 and hexadecimal tag encoding.
 */
@Test
public void legacyFormatCreation() {
  final File repoDir0 = tempDir.getRoot();
  final GitRepository repo0 = new GitRepository(proj, repoDir0, V0, commonPool(), 0L, Author.SYSTEM);
  try {
    assertThat(repo0.format()).isSameAs(V0);
    assertThat(Paths.get(repoDir0.getPath(), "refs", "heads", "master"))
        .existsNoFollowLinks()
        .isRegularFile();
  } finally {
    repo0.internalClose();
  }
}

代码示例来源:origin: line/centraldogma

/**
 * Makes sure {@link GitRepository} can create the modern format repository, with Git repository format
 * version 1 and simple tag encoding.
 */
@Test
public void modernFormatCreation() {
  final File repoDir1 = tempDir.getRoot();
  final GitRepository repo1 = new GitRepository(proj, repoDir1, commonPool(), 0L, Author.SYSTEM);
  try {
    assertThat(repo1.format()).isSameAs(V1);
    assertThat(Paths.get(repoDir1.getPath(), "refs", "heads", "master"))
        .existsNoFollowLinks()
        .isRegularFile();
  } finally {
    repo1.internalClose();
  }
}

相关文章