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

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

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

AbstractPathAssert.doesNotExist介绍

[英]Assert that the tested Path does not exist.

IMPORTANT NOTE: this method will NOT follow symbolic links (provided that the underlying FileSystem of this path supports symbolic links at all).

This means that even if the link exists this assertion will fail even if the link's target does not exists - note that this is unlike the default behavior of #exists().

If you are a Windows user, the above does not apply to you; if you are a Unix user however, this is important. Consider the following:

// fs is a 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 to a nonexistent target file. 
final Path nonExistentPath = fs.getPath("nonExistentPath"); 
final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath"); 
Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath); 
// The following assertion succeeds 
assertThat(nonExistentPath).doesNotExist(); 
// The following assertions fail: 
assertThat(existingFile).doesNotExist(); 
assertThat(symlinkToExistingFile).doesNotExist(); 
// fail because symlinkToNonExistentPath exists even though its target does not. 
assertThat(symlinkToNonExistentPath).doesNotExist();

[中]断言测试路径不存在。
重要提示:此方法不会遵循符号链接(前提是此路径的底层文件系统完全支持符号链接)。
这意味着,即使链接存在,即使链接的目标不存在,此断言也将失败-请注意,这与#exists()的默认行为不同。
如果您是Windows用户,上述规定不适用于您;但是,如果您是Unix用户,这一点很重要。考虑以下事项:

// fs is a 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 to a nonexistent target file. 
final Path nonExistentPath = fs.getPath("nonExistentPath"); 
final Path symlinkToNonExistentPath = fs.getPath("symlinkToNonExistentPath"); 
Files.createSymbolicLink(symlinkToNonExistentPath, nonExistentPath); 
// The following assertion succeeds 
assertThat(nonExistentPath).doesNotExist(); 
// The following assertions fail: 
assertThat(existingFile).doesNotExist(); 
assertThat(symlinkToExistingFile).doesNotExist(); 
// fail because symlinkToNonExistentPath exists even though its target does not. 
assertThat(symlinkToNonExistentPath).doesNotExist();

代码示例

代码示例来源:origin: apache/geode

@Test
 public void cleansUpAllTemporaryDirectories() throws IOException {
  DirectoryHolder directoryHolder2 = mock(DirectoryHolder.class);
  when(directoryHolder2.getDir()).thenReturn(baseTempDirectory.resolve("dir2").toFile());
  Path diskStoreDir = backupFiles.getDiskStoreDirectory(diskStore, directoryHolder);
  Path diskStoreDir2 = backupFiles.getDiskStoreDirectory(diskStore, directoryHolder2);

  backupFiles.cleanupFiles();

  assertThat(baseTempDirectory).doesNotExist();
  assertThat(diskStoreDir).doesNotExist();
  assertThat(diskStoreDir2).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 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 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 should_delete_report_by_default() throws IOException {
 Path reportDir = temp.getRoot().toPath().resolve("scanner-report");
 Files.createDirectory(reportDir);
 underTest.start();
 underTest.stop();
 assertThat(reportDir).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 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 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: SonarSource/sonarqube

@Test
public void log_but_not_dump_information_when_report_is_not_uploaded() throws IOException {
 underTest.logSuccess(/* report not uploaded, no server task */null);
 assertThat(logTester.logs(LoggerLevel.INFO))
  .contains("ANALYSIS SUCCESSFUL")
  .doesNotContain("dashboard/index");
 assertThat(properties.metadataFilePath()).doesNotExist();
}

代码示例来源:origin: spring-projects/spring-kafka

@Test
public void testCleanupStreams() throws IOException {
  Path stateStore = Files.createDirectory(Paths.get(stateStoreDir.toString(), APPLICATION_ID, "0_0"));
  assertThat(stateStore).exists();
  streamsBuilderFactoryBean.stop();
  assertThat(stateStore).doesNotExist();
  stateStore = Files.createDirectory(Paths.get(stateStoreDir.toString(), APPLICATION_ID, "0_0"));
  assertThat(stateStore).exists();
  streamsBuilderFactoryBean.start();
  assertThat(stateStore).doesNotExist();
}

代码示例来源:origin: HubSpot/Singularity

@Test
public void itAbsorbsFileAlreadyExistsExceptionsWhenCopyingDuplicateFiles() {
 List<String> lines = Arrays.asList("Testing", "1", "2", "3");
 Path originalPath = write("original.txt", lines);
 assertThat(originalPath.toFile()).hasContent(String.join(System.lineSeparator(), lines));
 Path copyPath = Paths.get(cacheDir.getRoot().toString() + "/copy.txt");
 assertThat(copyPath).doesNotExist();
 artifactManager.copy(originalPath, cacheDir.getRoot().toPath(), "copy.txt");
 assertThat(copyPath).exists();
 // A redundant copy operation should not throw.
 artifactManager.copy(originalPath, cacheDir.getRoot().toPath(), "copy.txt");
}

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

@Test
@Category( { Writable.class, Delete.class, MoveWhile.class } )
public void testDeleteWhileWriting() throws IOException {
  Path file = fileTA();
  try( ByteChannel ch = Files.newByteChannel( file, Sets.asSet( WRITE ) ) ) {
    Files.delete( file );
    assertThat( file ).doesNotExist();
    ch.write( ByteBuffer.wrap( CONTENT_OTHER ) );
  }
  assertThat( file ).doesNotExist();
}

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

@Test
@Category( { SymLink.class, Writable.class, Delete.class } )
public void testSymLinkLoopCanBeDeleted() throws IOException {
  Files.createSymbolicLink( symLink(), symLink().getParent() );
  Files.delete( symLink() );
  assertThat( symLink() ).doesNotExist();
}

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

@Test
@Category( { SymLink.class, Writable.class, Delete.class } )
public void testDeleteSymLinkDoesNotDeleteTarget() throws IOException {
  Files.createSymbolicLink( symLink(), targetFile() );
  Files.delete( symLink() );
  assertThat( targetFile() ).exists();
  assertThat( symLink() ).doesNotExist();
}

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

@Test
@Category( { SymLink.class } )
public void testMoveSymLinkMovesLink() throws IOException {
  Files.createSymbolicLink( symLink(), targetFile() );
  Files.move( symLink(), absTC() );
  assertThat( symLink() ).doesNotExist();
}

代码示例来源:origin: SonarSource/sonarlint-intellij

@Test
public void testDelete() throws IOException {
 store.write("mykey", "myvalue");
 assertThat(getPath("mykey")).hasContent("myvalue");
 store.delete("mykey");
 assertThat(store.read("mykey").isPresent()).isFalse();
 assertThat(getPath("mykey")).doesNotExist();
 verify(index).delete("mykey");
}

相关文章