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

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

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

AbstractPathAssert.exists介绍

[英]Assert that the tested Path exists according to Files#exists(Path,LinkOption...))

Note that this assertion will follow symbolic links before asserting the path's existence.

On Windows system, this has no influence. On Unix systems, this means the assertion result will fail if the path is a symbolic link whose target does not exist. If you want to assert the existence of the symbolic link itself, use #existsNoFollowLinks() instead.
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("symlinkToExistingFile"); 
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).exists(); 
assertThat(symlinkToExistingFile).exists(); 
// The following assertions fail: 
assertThat(nonExistentPath).exists(); 
assertThat(symlinkToNonExistentPath).exists();

[中]根据文件#exists(Path,LinkOption…)断言测试路径存在
请注意,在断言路径的存在之前,此断言将遵循符号链接。
在Windows系统上,这没有影响。在Unix系统上,这意味着如果路径是目标不存在的符号链接,则断言结果将失败。如果要断言符号链接本身的存在,请改用#existsnoflowlinks()。
示例:

// 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("symlinkToExistingFile"); 
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).exists(); 
assertThat(symlinkToExistingFile).exists(); 
// The following assertions fail: 
assertThat(nonExistentPath).exists(); 
assertThat(symlinkToNonExistentPath).exists();

代码示例

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

@Override
protected void before() throws IOException {
 gfsh = findGfsh();
 assertThat(gfsh).exists();
 gfshExecutions = new ArrayList<>();
 temporaryFolder.create();
}

代码示例来源:origin: springside/springside4

@Test
public void testMakesureDirExists() throws Exception {
  Path dir = FileUtil.createTempDir();
  String child1 = "child1";
  Path child1Dir = dir.resolve(child1);
  FileUtil.makesureDirExists(child1Dir.toString());
  assertThat(child1Dir).exists();
  String child2 = "child2";
  Path child2Dir = dir.resolve(child2);
  FileUtil.makesureDirExists(child2Dir);
  assertThat(child2Dir).exists();
  String child3 = "child3";
  Path child3Dir = dir.resolve(child3);
  FileUtil.makesureDirExists(child3Dir.toFile());
  assertThat(child3Dir).exists();
}

代码示例来源:origin: allure-framework/allure2

@Test
public void shouldCreateCsvFile() throws IOException {
  final SuitesPlugin plugin = new SuitesPlugin();
  plugin.aggregate(configuration, getSimpleLaunchResults(), reportPath);
  assertThat(reportPath.resolve("data").resolve(JSON_FILE_NAME))
      .exists();
  assertThat(reportPath.resolve("data").resolve(CSV_FILE_NAME))
      .exists();
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void testSaveToFile()
  throws IOException {
 FileUtils utils = new FileUtils();
 Path destPath = Paths.get("fileUtilTest.txt");
 utils.saveToFile("foo", destPath);
 assertThat(destPath).exists().isReadable().hasContent("foo\n");
 Files.deleteIfExists(destPath);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void tryLock() {
 assertThat(temp.getRoot().list()).isEmpty();
 lock.tryLock();
 assertThat(temp.getRoot().toPath().resolve(".sonar_lock")).exists();
 lock.unlock();
}

代码示例来源:origin: springside/springside4

@Test
public void testCopy() throws Exception {
  Path dir = FileUtil.createTempDir();
  assertThat(dir).exists();
  String srcFileName = "src";
  File srcFile = dir.resolve(srcFileName).toFile();
  FileUtil.touch(srcFile);
  assertThat(srcFile).exists();
  FileUtil.write("test", srcFile);
  String destFileName = "dest";
  File destFile = new File(dir.toFile(), "parent1/parent2/" + destFileName);
  FileUtil.makesureParentDirExists(destFile);
  FileUtil.copy(srcFile, destFile);
  assertThat(Files.readFirstLine(destFile, Charsets.UTF_8)).isEqualTo("test");
}

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

@Test
public void returnsCreatedDirectoryForADiskStore() throws IOException {
 Path diskStoreDir = backupFiles.getDiskStoreDirectory(diskStore, directoryHolder);
 assertThat(diskStoreDir)
   .isEqualTo(directoryHolder.getDir().toPath().resolve(DISK_STORE_DIR_NAME));
 assertThat(diskStoreDir).exists();
}

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

@Test
public void factoryMethodCreatesValidInstance() throws IOException {
 TemporaryBackupFiles backupFiles = TemporaryBackupFiles.create();
 assertThat(backupFiles.getDirectory()).exists();
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void log_and_dump_information_to_custom_path() throws IOException {
 underTest.logSuccess("TASK-123");
 assertThat(properties.metadataFilePath()).exists();
 assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Report metadata written to " + properties.metadataFilePath());
}

代码示例来源:origin: cbeust/testng

@Test(dataProvider = "dp")
public void runFailedTestTwiceShouldBeConsistent(Class<?> testClass, String[] succeedMethods, String[] failedMethods) throws IOException {
 Path outputDirectory = TestHelper.createRandomDirectory();
 TestNG tng = create(outputDirectory, testClass);
 InvokedMethodNameListener listener = new InvokedMethodNameListener();
 tng.addListener(listener);
 tng.addListener(new FailedReporter());
 tng.run();
 assertThat(listener.getFailedMethodNames()).containsExactly(failedMethods);
 assertThat(listener.getSucceedMethodNames()).containsExactly(succeedMethods);
 assertThat(listener.getSkippedMethodNames()).isEmpty();
 Path testngFailedXml = outputDirectory.resolve(FailedReporter.TESTNG_FAILED_XML);
 assertThat(testngFailedXml).exists();
 for (int i = 0; i < 5; i++) {
  testngFailedXml = checkFailed(testngFailedXml, failedMethods);
 }
}

代码示例来源:origin: cbeust/testng

private static Path checkFailed(Path testngFailedXml, String... failedMethods) throws IOException {
  Path outputDirectory = TestHelper.createRandomDirectory();

  List<XmlSuite> suites = new Parser(Files.newInputStream(testngFailedXml)).parseToList();
  TestNG tng = create(outputDirectory, suites);
  InvokedMethodNameListener listener = new InvokedMethodNameListener();
  tng.addListener(listener);
  tng.addListener(new FailedReporter());

  tng.run();

  assertThat(listener.getSucceedMethodNames()).isEmpty();
  assertThat(listener.getSkippedMethodNames()).isEmpty();
  assertThat(listener.getFailedMethodNames()).containsExactly(failedMethods);

  Path testngFailedXml2 = outputDirectory.resolve(FailedReporter.TESTNG_FAILED_XML);
  assertThat(testngFailedXml2).exists();

  return testngFailedXml2;
 }
}

代码示例来源:origin: allure-framework/allure2

@Test
public void shouldWork() throws IOException {
  Category category = new Category()
      .setName(CATEGORY_NAME)
      .setMessageRegex(".*")
      .setMatchedStatuses(singletonList(Status.BROKEN));
  Map<String, Object> meta = new HashMap<>();
  meta.put("categories", singletonList(category));
  List<LaunchResults> launchResultsList = createSingleLaunchResults(
      meta, createTestResult("asd\n", Status.BROKEN)
  );
  CategoriesPlugin plugin = new CategoriesPlugin();
  plugin.aggregate(configuration, launchResultsList, reportPath);
  Set<TestResult> results = launchResultsList.get(0).getAllResults();
  List<Category> categories = results.toArray(new TestResult[]{})[0]
      .getExtraBlock("categories");
  assertThat(categories).as("test categories")
      .extracting(Category::getName)
      .containsExactly(category.getName());
  assertThat(reportPath.resolve("data").resolve(JSON_FILE_NAME))
      .exists();
  assertThat(reportPath.resolve("data").resolve(CSV_FILE_NAME))
      .exists();
}

代码示例来源:origin: allure-framework/allure2

@Test
public void flakyTestsCanBeAddedToCategory() throws IOException {
  Category category = new Category()
      .setName(CATEGORY_NAME)
      .setMatchedStatuses(singletonList(Status.FAILED))
      .setFlaky(true);
  Map<String, Object> meta = new HashMap<>();
  meta.put("categories", singletonList(category));
  List<LaunchResults> launchResultsList = createSingleLaunchResults(
      meta, createTestResult("asd\n", Status.FAILED, true)
  );
  CategoriesPlugin plugin = new CategoriesPlugin();
  plugin.aggregate(configuration, launchResultsList, reportPath);
  Set<TestResult> results = launchResultsList.get(0).getAllResults();
  List<Category> categories = results.toArray(new TestResult[]{})[0]
      .getExtraBlock("categories");
  assertThat(categories).as("test categories")
      .extracting(Category::getName)
      .containsExactly(category.getName());
  assertThat(reportPath.resolve("data").resolve(JSON_FILE_NAME))
      .exists();
}

代码示例来源: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: hcoles/pitest

@Test
public void shouldCreateAMutantsDirectoryForEachClass() {
 this.testee.begin(tree(Foo.class));
 this.testee.begin(tree(String.class));
 assertThat(this.fileSystem.getPath("target", "export", "org", "pitest", "plugin", "export", "Foo", "mutants")).exists();
 assertThat(this.fileSystem.getPath("target", "export", "java", "lang", "String", "mutants")).exists();
}

代码示例来源: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: hcoles/pitest

@Test
public void shouldWriteDisassembledOriginalBytecodeToDisk() {
 executeFor(VeryMutable.class);
 final Path shouldBeCreated = classBasePath(VeryMutable.class).resolve(ClassName.fromClass(VeryMutable.class).asJavaName() + ".txt");
 assertThat(shouldBeCreated).exists();
}

代码示例来源:origin: hcoles/pitest

@Test
public void shouldWriteDissasembledMutantBytecodeToDisk() {
 executeFor(VeryMutable.class);
 final Path shouldBeCreated = mutantBasePath(VeryMutable.class,0).resolve(ClassName.fromClass(VeryMutable.class).asJavaName() + ".txt");
 assertThat(shouldBeCreated).exists();
}

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

@Test
@Category( Writable.class )
public void testOverwriteTruncateExisting() throws IOException {
  Path there = fileTA();
  try( SeekableByteChannel ch = FS.provider().newByteChannel( there, asSet( WRITE, TRUNCATE_EXISTING ) ) ) {
  }
  assertThat( there ).exists();
  assertThat( Files.size( there ) ).isEqualTo( 0L );
}

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

@Test
public void testSave() {
 Path test1 = baseDir.resolve("p1").resolve("file1");
 index.save("key1", test1);
 assertThat(baseDir.resolve(StringStoreIndex.INDEX_FILENAME)).exists();
 assertThat(index.keys()).containsOnly("key1");
}

相关文章