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

x33g5p2x  于2022-01-15 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(121)

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

AbstractFileAssert.isDirectory介绍

[英]Verifies that the actual File is an existing directory.

Example:

File tmpDir = Files.createTempDirectory("tmpDir").toFile(); 
// assertion will pass 
assertThat(tmpDir).isDirectory(); 
tmpDir.delete(); 
File tmpFile = File.createTempFile("tmp", "txt"); 
// assertions will fail 
assertThat(tmpFile).isDirectory(); 
assertThat(tmpDir).isDirectory();

[中]验证实际文件是否为现有目录。
例子:

File tmpDir = Files.createTempDirectory("tmpDir").toFile(); 
// assertion will pass 
assertThat(tmpDir).isDirectory(); 
tmpDir.delete(); 
File tmpFile = File.createTempFile("tmp", "txt"); 
// assertions will fail 
assertThat(tmpFile).isDirectory(); 
assertThat(tmpDir).isDirectory();

代码示例

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

private File getCreatedTempDir(File workingDir) {
 assertThat(workingDir).isDirectory();
 assertThat(workingDir.listFiles()).hasSize(1);
 return workingDir.listFiles()[0];
}

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

@Test
public void reset_creates_dirs_if_they_don_t_exist() throws Exception {
 assertThat(dataDir).doesNotExist();
 underTest.reset();
 assertThat(dataDir).exists().isDirectory();
 assertThat(logsDir).exists().isDirectory();
 assertThat(tempDir).exists().isDirectory();
 assertThat(webDir).exists().isDirectory();
 underTest.reset();
 assertThat(dataDir).exists().isDirectory();
 assertThat(logsDir).exists().isDirectory();
 assertThat(tempDir).exists().isDirectory();
 assertThat(webDir).exists().isDirectory();
}

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

@Test
public void existing_temp_dir() throws Exception {
 ServerFileSystem fs = mock(ServerFileSystem.class);
 File tmpDir = temp.newFolder();
 when(fs.getTempDir()).thenReturn(tmpDir);
 TempFolder folder = underTest.provide(fs);
 assertThat(folder).isNotNull();
 File newDir = folder.newDir();
 assertThat(newDir).exists().isDirectory();
 assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath());
}

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

@Test
public void create_dir_if_does_not_exist() {
 FileUtils.deleteQuietly(dir);
 underTest = new ScannerReportWriter(dir);
 assertThat(dir).isDirectory().exists();
}

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

@Test
 public void create_temp_dir_if_missing() throws Exception {
  ServerFileSystem fs = mock(ServerFileSystem.class);
  File tmpDir = temp.newFolder();
  when(fs.getTempDir()).thenReturn(tmpDir);
  FileUtils.forceDelete(tmpDir);

  TempFolder folder = underTest.provide(fs);
  assertThat(folder).isNotNull();
  File newDir = folder.newDir();
  assertThat(newDir).exists().isDirectory();
  assertThat(newDir.getParentFile().getCanonicalPath()).startsWith(tmpDir.getCanonicalPath());
 }
}

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

@Test
public void shouldDefineProjectWithBuildDir() {
 ProjectDefinition rootProject = loadProjectDefinition("simple-project-with-build-dir");
 File buildDir = rootProject.getBuildDir();
 assertThat(buildDir).isDirectory().exists();
 assertThat(new File(buildDir, "report.txt")).isFile().exists();
 assertThat(buildDir.getName()).isEqualTo("build");
}

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

@Test
public void test_directories() throws Exception {
 assertThat(fs.baseDir()).isAbsolute().isDirectory().exists();
 assertThat(fs.baseDir().getCanonicalPath()).isEqualTo(basedir.getCanonicalPath());
 File workdir = temp.newFolder();
 fs.setWorkDir(workdir.toPath());
 assertThat(fs.workDir()).isAbsolute().isDirectory().exists();
 assertThat(fs.workDir().getCanonicalPath()).isEqualTo(workdir.getCanonicalPath());
}

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

@Test
public void create_dir_and_configure_static_directory() throws Exception {
 File dir = temp.newFolder();
 dir.delete();
 underTest.addStaticDir(tomcat, "/deploy", dir);
 assertThat(dir).isDirectory().exists();
 verify(tomcat).addWebapp("/deploy", dir.getAbsolutePath());
}

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

@Test
public void explode_jar_to_temp_directory() {
 PluginInfo info = PluginInfo.create(plugin1Jar());
 ExplodedPlugin exploded = underTest.explode(info);
 // all the files loaded by classloaders (JAR + META-INF/libs/*.jar) are copied to a dedicated temp directory
 File copiedJar = exploded.getMain();
 assertThat(exploded.getKey()).isEqualTo("test");
 assertThat(copiedJar).isFile().exists();
 assertThat(copiedJar.getParentFile()).isDirectory().hasName("test");
 assertThat(copiedJar.getParentFile().getParentFile()).isDirectory().hasName("ce-exploded-plugins");
}

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

@Test
public void create_uninstall_dir() {
 File dir = new File(testFolder.getRoot(), "dir");
 when(fs.getUninstalledPluginsDir()).thenReturn(dir);
 underTest = new PluginUninstaller(serverPluginRepository, fs);
 underTest.start();
 assertThat(dir).isDirectory();
}

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

@Test
public void cleanup_static_directory_if_already_exists() throws Exception {
 File dir = temp.newFolder();
 FileUtils.touch(new File(dir, "foo.txt"));
 underTest.addStaticDir(tomcat, "/deploy", dir);
 assertThat(dir).isDirectory().exists();
 assertThat(dir.listFiles()).isEmpty();
}

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

@Test
 public void detectHomeDir_returns_existing_dir() {
  assertThat(new AppSettingsLoaderImpl(new String[0]).getHomeDir()).exists().isDirectory();

 }
}

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

@Test
 public void should_stop_and_clean_temp_dir() {
  File tempDir = cachesManager.tempDir();
  assertThat(tempDir).isDirectory().exists();
  assertThat(cachesManager.persistit()).isNotNull();
  assertThat(cachesManager.persistit().isInitialized()).isTrue();

  cachesManager.stop();

  assertThat(tempDir).doesNotExist();
  assertThat(cachesManager.tempDir()).isNull();
  assertThat(cachesManager.persistit()).isNull();
 }
}

代码示例来源:origin: spring-io/initializr

/**
 * Validate that the project contains a base directory with the specified name.
 * <p>
 * When extracting such archive, a directory with the specified {@code name} will be
 * created with the content of the project instead of extracting it in the directory
 * itself.
 * @param name the expected name of the base directory
 * @return an updated project assert on that base directory
 */
public ProjectAssert hasBaseDir(String name) {
  File projectDir = file(name);
  assertThat(projectDir).describedAs("No directory %s found in %s", name,
      this.dir.getAbsolutePath()).exists();
  assertThat(projectDir).isDirectory();
  // Replacing the root dir so that other assertions match the root
  return new ProjectAssert(projectDir);
}

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

@Test
public void createTempFolderWithName() throws Exception {
 File rootTempFolder = temp.newFolder();
 DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder);
 File dir = underTest.newDir("sample");
 assertThat(dir).exists().isDirectory();
 assertThat(new File(rootTempFolder, "sample")).isEqualTo(dir);
 new TempFolderCleaner(underTest).stop();
 assertThat(rootTempFolder).doesNotExist();
}

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

@Test
public void apply() throws Throwable {
 JUnitTempFolder temp = new JUnitTempFolder();
 temp.before();
 File dir1 = temp.newDir();
 assertThat(dir1).isDirectory().exists();
 File dir2 = temp.newDir("foo");
 assertThat(dir2).isDirectory().exists();
 File file1 = temp.newFile();
 assertThat(file1).isFile().exists();
 File file2 = temp.newFile("foo", "txt");
 assertThat(file2).isFile().exists();
 temp.after();
 assertThat(dir1).doesNotExist();
 assertThat(dir2).doesNotExist();
 assertThat(file1).doesNotExist();
 assertThat(file2).doesNotExist();
}

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

@Test
public void createTempFolderAndFile() throws Exception {
 File rootTempFolder = temp.newFolder();
 DefaultTempFolder underTest = new DefaultTempFolder(rootTempFolder);
 File dir = underTest.newDir();
 assertThat(dir).exists().isDirectory();
 File file = underTest.newFile();
 assertThat(file).exists().isFile();
 new TempFolderCleaner(underTest).stop();
 assertThat(rootTempFolder).doesNotExist();
}

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

@Test
public void unzip_report() throws Exception {
 logTester.setLevel(LoggerLevel.DEBUG);
 File reportFile = generateReport();
 try (InputStream input = FileUtils.openInputStream(reportFile)) {
  dbTester.getDbClient().ceTaskInputDao().insert(dbTester.getSession(), TASK_UUID, input);
 }
 dbTester.getSession().commit();
 dbTester.getSession().close();
 underTest.execute(new TestComputationStepContext());
 // directory contains the uncompressed report (which contains only metadata.pb in this test)
 File unzippedDir = reportDirectoryHolder.getDirectory();
 assertThat(unzippedDir).isDirectory().exists();
 assertThat(unzippedDir.listFiles()).hasSize(1);
 assertThat(new File(unzippedDir, "metadata.pb")).hasContent("{metadata}");
 assertThat(logTester.logs(LoggerLevel.DEBUG)).anyMatch(log -> log.matches("Analysis report is \\d+ bytes uncompressed"));
}

代码示例来源:origin: org.apache.james/james-server-filesystem-api

@Test
public final void protocolWithDoubleSlashesOnlyShouldReturnDir() throws Exception {
  File file = fileSystem.getFile("file://");
  assertThat(file).isDirectory();
}

代码示例来源:origin: kiegroup/appformer

@Test
public void createDirectory() {
  final Path path = newTempDir();
  final Path dir = Files.createDirectory(path.resolve("myNewDir"));
  assertThat(dir).isNotNull();
  assertThat(dir.toFile()).exists();
  assertThat(dir.toFile()).isDirectory();
  final Path file = Files.createFile(dir.resolve("new.file.txt"));
  assertThat(file).isNotNull();
  assertThat(file.toFile()).exists();
  assertThat(file.toFile()).isFile();
}

相关文章