本文整理了Java中org.assertj.core.api.AbstractFileAssert.exists()
方法的一些代码示例,展示了AbstractFileAssert.exists()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractFileAssert.exists()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractFileAssert
类名称:AbstractFileAssert
方法名:exists
[英]Verifies that the actual File exists, regardless it's a file or directory.
Example:
File tmpFile = File.createTempFile("tmp", "txt");
File tmpDir = Files.createTempDirectory("tmpDir").toFile();
// assertions will pass
assertThat(tmpFile).exists();
assertThat(tmpDir).exists();
tmpFile.delete();
tmpDir.delete();
// assertions will fail
assertThat(tmpFile).exists();
assertThat(tmpDir).exists();
[中]验证实际文件是否存在,无论它是文件还是目录。
例子:
File tmpFile = File.createTempFile("tmp", "txt");
File tmpDir = Files.createTempDirectory("tmpDir").toFile();
// assertions will pass
assertThat(tmpFile).exists();
assertThat(tmpDir).exists();
tmpFile.delete();
tmpDir.delete();
// assertions will fail
assertThat(tmpFile).exists();
assertThat(tmpDir).exists();
代码示例来源:origin: SonarSource/sonarqube
private static void verifySameContent(File file1, FileAndMd5 file2) {
assertThat(file1).isFile().exists();
assertThat(file2.file).isFile().exists();
assertThat(file1).hasSameContentAs(file2.file);
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldCreateDesEncryptorIfCipherFileIsPresent() throws IOException {
resetCipher.setupDESCipherFile();
assertThat(desCipherFile).exists();
GoCipher goCipher = new GoCipher(systemEnvironment);
assertThat(goCipher.aesEncrypter).isNotNull();
assertThat(goCipher.desEncrypter).isNotNull();
}
代码示例来源: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
/**
* Packing and unpacking a JAR generates a different file.
*/
private void verifySameContentAfterCompression(File file1, File file2) throws IOException {
assertThat(file1).isFile().exists();
assertThat(file2).isFile().exists();
assertThat(packAndUnpackJar(file1)).hasSameContentAs(packAndUnpackJar(file2));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void copy_and_extract_libs() throws IOException {
File jar = loadFile("sonar-checkstyle-plugin-2.8.jar");
ExplodedPlugin exploded = underTest.explode(PluginInfo.create(jar));
assertThat(exploded.getKey()).isEqualTo("checkstyle");
assertThat(exploded.getMain()).isFile().exists();
assertThat(exploded.getLibs()).extracting(File::getName).containsExactlyInAnyOrder("antlr-2.7.6.jar", "checkstyle-5.1.jar", "commons-cli-1.0.jar");
assertThat(new File(jar.getParent(), "sonar-checkstyle-plugin-2.8.jar")).exists();
assertThat(new File(jar.getParent(), "sonar-checkstyle-plugin-2.8.jar_unzip/META-INF/lib/checkstyle-5.1.jar")).exists();
}
代码示例来源: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 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 test_generation_of_file() throws IOException {
File yamlFile = temp.newFile();
new EsYmlSettings(new HashMap<>()).writeToYmlSettingsFile(yamlFile);
assertThat(yamlFile).exists();
assertThat(yamlFile).hasContent("# This file has been automatically generated by SonarQube during startup.\n" +
"\n" +
"# DO NOT EDIT THIS FILE\n" +
"\n" +
"{\n" +
" }");
}
代码示例来源: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 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 createTempFolderSonarHome() throws Exception {
// with sonar home, it will be in {sonar.home}/.sonartmp
File sonarHome = temp.newFolder();
File workingDir = new File(sonarHome, CoreProperties.GLOBAL_WORKING_DIRECTORY_DEFAULT_VALUE).getAbsoluteFile();
TempFolder tempFolder = tempFolderProvider.provide(new ScannerProperties(ImmutableMap.of("sonar.userHome", sonarHome.getAbsolutePath())));
tempFolder.newDir();
tempFolder.newFile();
assertThat(getCreatedTempDir(workingDir)).exists();
assertThat(getCreatedTempDir(workingDir).list()).hasSize(2);
FileUtils.deleteQuietly(sonarHome);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void createTempFolder() throws IOException {
File defaultDir = new File(temp.getRoot(), AnalysisTempFolderProvider.TMP_NAME);
TempFolder tempFolder = tempFolderProvider.provide(project);
tempFolder.newDir();
tempFolder.newFile();
assertThat(defaultDir).exists();
assertThat(defaultDir.list()).hasSize(2);
}
}
代码示例来源: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 contextProperties_file() throws Exception {
File dir = temp.newFolder();
File file = new File(dir, "context-props.pb");
FileUtils.write(file, "content");
FileStructure structure = new FileStructure(dir);
assertThat(structure.contextProperties()).exists().isFile().isEqualTo(file);
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void downloadToFile() throws URISyntaxException, IOException {
File toDir = temporaryFolder.newFolder();
File toFile = new File(toDir, "downloadToFile.txt");
new DefaultHttpDownloader(new MapSettings().asConfig()).download(new URI(baseUrl), toFile);
assertThat(toFile).exists();
assertThat(toFile.length()).isGreaterThan(10l);
}
代码示例来源: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 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 install_downloaded_plugins_on_startup() throws Exception {
File downloadedJar = copyTestPluginTo("test-base-plugin", fs.getDownloadedPluginsDir());
underTest.start();
// plugin is moved to extensions/plugins then loaded
assertThat(downloadedJar).doesNotExist();
assertThat(new File(fs.getInstalledPluginsDir(), downloadedJar.getName())).isFile().exists();
assertThat(underTest.getPluginInfosByKeys()).containsOnlyKeys("testbase");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void plugins_do_not_overlap() {
PluginInfo info1 = PluginInfo.create(plugin1Jar());
PluginInfo info2 = PluginInfo.create(plugin2Jar());
ExplodedPlugin exploded1 = underTest.explode(info1);
ExplodedPlugin exploded2 = underTest.explode(info2);
assertThat(exploded1.getKey()).isEqualTo("test");
assertThat(exploded1.getMain()).isFile().exists().hasName("sonar-test-plugin-0.1-SNAPSHOT.jar");
assertThat(exploded2.getKey()).isEqualTo("test2");
assertThat(exploded2.getMain()).isFile().exists().hasName("sonar-test2-plugin-0.1-SNAPSHOT.jar");
}
代码示例来源: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();
}
内容来源于网络,如有侵权,请联系作者删除!