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

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

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

AbstractFileAssert.isFile介绍

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

Example:

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

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

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

代码示例

代码示例来源: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: 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 zip_directory() throws IOException {
 File foo = FileUtils.toFile(getClass().getResource("/org/sonar/api/utils/ZipUtilsTest/shouldZipDirectory/foo.txt"));
 File dir = foo.getParentFile();
 File zip = temp.newFile();
 ZipUtils.zipDir(dir, zip);
 assertThat(zip).exists().isFile();
 assertThat(zip.length()).isGreaterThan(1L);
 Iterator<? extends ZipEntry> zipEntries = Iterators.forEnumeration(new ZipFile(zip).entries());
 assertThat(zipEntries).hasSize(4);
 File unzipDir = temp.newFolder();
 ZipUtils.unzip(zip, unzipDir);
 assertThat(new File(unzipDir, "bar.txt")).exists().isFile();
 assertThat(new File(unzipDir, "foo.txt")).exists().isFile();
 assertThat(new File(unzipDir, "dir1/hello.properties")).exists().isFile();
}

代码示例来源: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 locate_files() throws Exception {
 File dir = temp.newFolder();
 FileUtils.write(new File(dir, "metadata.pb"), "metadata content");
 FileUtils.write(new File(dir, "issues-3.pb"), "external issues of component 3");
 FileUtils.write(new File(dir, "external-issues-3.pb"), "issues of component 3");
 FileUtils.write(new File(dir, "component-42.pb"), "details of component 42");
 FileStructure structure = new FileStructure(dir);
 assertThat(structure.metadataFile()).exists().isFile();
 assertThat(structure.fileFor(FileStructure.Domain.COMPONENT, 42)).exists().isFile();
 assertThat(structure.fileFor(FileStructure.Domain.ISSUES, 3)).exists().isFile();
 assertThat(structure.fileFor(FileStructure.Domain.ISSUES, 42)).doesNotExist();
 assertThat(structure.fileFor(FileStructure.Domain.EXTERNAL_ISSUES, 3)).exists().isFile();
 assertThat(structure.fileFor(FileStructure.Domain.EXTERNAL_ISSUES, 42)).doesNotExist();
}

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

@Test
public void download_installed_plugins() throws IOException {
 WsTestUtil.mockReader(wsClient, "api/plugins/installed", new InputStreamReader(getClass().getResourceAsStream("ScannerPluginInstallerTest/installed-plugins-ws.json")));
 enqueueDownload("scmgit", "abc");
 enqueueDownload("java", "def");
 when(pluginPredicate.apply(any())).thenReturn(true);
 Map<String, ScannerPlugin> result = underTest.installRemotes();
 assertThat(result.keySet()).containsExactlyInAnyOrder("scmgit", "java");
 ScannerPlugin gitPlugin = result.get("scmgit");
 assertThat(gitPlugin.getKey()).isEqualTo("scmgit");
 assertThat(gitPlugin.getInfo().getNonNullJarFile()).exists().isFile();
 assertThat(gitPlugin.getUpdatedAt()).isEqualTo(100L);
 ScannerPlugin javaPlugin = result.get("java");
 assertThat(javaPlugin.getKey()).isEqualTo("java");
 assertThat(javaPlugin.getInfo().getNonNullJarFile()).exists().isFile();
 assertThat(javaPlugin.getUpdatedAt()).isEqualTo(200L);
}

代码示例来源: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 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 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 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 write_issues() {
 // no data yet
 assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isFalse();
 // write data
 ScannerReport.Issue issue = ScannerReport.Issue.newBuilder()
  .setMsg("the message")
  .build();
 underTest.writeComponentIssues(1, asList(issue));
 assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue();
 File file = underTest.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1);
 assertThat(file).exists().isFile();
 try (CloseableIterator<ScannerReport.Issue> read = Protobuf.readStream(file, ScannerReport.Issue.parser())) {
  assertThat(Iterators.size(read)).isEqualTo(1);
 }
}

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

@Test
public void write_external_issues() {
 // no data yet
 assertThat(underTest.hasComponentData(FileStructure.Domain.EXTERNAL_ISSUES, 1)).isFalse();
 // write data
 ScannerReport.ExternalIssue issue = ScannerReport.ExternalIssue.newBuilder()
  .setMsg("the message")
  .build();
 underTest.appendComponentExternalIssue(1, issue);
 assertThat(underTest.hasComponentData(FileStructure.Domain.EXTERNAL_ISSUES, 1)).isTrue();
 File file = underTest.getFileStructure().fileFor(FileStructure.Domain.EXTERNAL_ISSUES, 1);
 assertThat(file).exists().isFile();
 try (CloseableIterator<ScannerReport.ExternalIssue> read = Protobuf.readStream(file, ScannerReport.ExternalIssue.parser())) {
  assertThat(Iterators.size(read)).isEqualTo(1);
 }
}

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

@Test
public void write_changed_lines() {
 assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGED_LINES, 1)).isFalse();
 ScannerReport.ChangedLines changedLines = ScannerReport.ChangedLines.newBuilder()
  .addLine(1)
  .addLine(3)
  .build();
 underTest.writeComponentChangedLines(1, changedLines);
 assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGED_LINES, 1)).isTrue();
 File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CHANGED_LINES, 1);
 assertThat(file).exists().isFile();
 ScannerReport.ChangedLines loadedChangedLines = Protobuf.read(file, ScannerReport.ChangedLines.parser());
 assertThat(loadedChangedLines.getLineList()).containsExactly(1, 3);
}

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

@Test
public void write_measures() {
 assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse();
 ScannerReport.Measure measure = ScannerReport.Measure.newBuilder()
  .setDoubleValue(DoubleValue.newBuilder().setValue(2.5d).setData("text-value"))
  .build();
 underTest.writeComponentMeasures(1, asList(measure));
 assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isTrue();
 File file = underTest.getFileStructure().fileFor(FileStructure.Domain.MEASURES, 1);
 assertThat(file).exists().isFile();
 try (CloseableIterator<ScannerReport.Measure> read = Protobuf.readStream(file, ScannerReport.Measure.parser())) {
  assertThat(Iterators.size(read)).isEqualTo(1);
 }
}

代码示例来源: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 copy_and_use_existing_packed_jar_if_compression_enabled() throws IOException {
 File jar = touch(temp.newFolder(), "sonar-foo-plugin.jar");
 File packedJar = touch(jar.getParentFile(), "sonar-foo-plugin.pack.gz");
 PluginInfo info = new PluginInfo("foo").setJarFile(jar);
 // the JAR is copied somewhere else in order to be loaded by classloaders
 File loadedJar = touch(temp.newFolder(), "sonar-foo-plugin.jar");
 settings.setProperty(PROPERTY_PLUGIN_COMPRESSION_ENABLE, true);
 PluginFileSystem underTest = new PluginFileSystem(settings.asConfig());
 underTest.addInstalledPlugin(info, loadedJar);
 assertThat(underTest.getInstalledFiles()).hasSize(1);
 InstalledPlugin installedPlugin = underTest.getInstalledPlugin("foo").get();
 assertThat(installedPlugin.getPluginInfo()).isSameAs(info);
 assertThat(installedPlugin.getLoadedJar().getFile().toPath()).isEqualTo(loadedJar.toPath());
 assertThat(installedPlugin.getCompressedJar().getFile())
  .exists()
  .isFile()
  .hasName(packedJar.getName())
  .hasParent(loadedJar.getParentFile())
  .hasSameContentAs(packedJar);
}

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

@Test
public void compress_jar_if_compression_enabled() throws IOException {
 File jar = touch(temp.newFolder(), "sonar-foo-plugin.jar");
 PluginInfo info = new PluginInfo("foo").setJarFile(jar);
 // the JAR is copied somewhere else in order to be loaded by classloaders
 File loadedJar = touch(temp.newFolder(), "sonar-foo-plugin.jar");
 settings.setProperty(PROPERTY_PLUGIN_COMPRESSION_ENABLE, true);
 PluginFileSystem underTest = new PluginFileSystem(settings.asConfig());
 underTest.addInstalledPlugin(info, loadedJar);
 assertThat(underTest.getInstalledFiles()).hasSize(1);
 InstalledPlugin installedPlugin = underTest.getInstalledPlugin("foo").get();
 assertThat(installedPlugin.getPluginInfo()).isSameAs(info);
 assertThat(installedPlugin.getLoadedJar().getFile().toPath()).isEqualTo(loadedJar.toPath());
 assertThat(installedPlugin.getCompressedJar().getFile())
  .exists()
  .isFile()
  .hasName("sonar-foo-plugin.pack.gz")
  .hasParent(loadedJar.getParentFile());
}

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

@Test
public void write_adhoc_rule() {
 // write data
 ScannerReport.AdHocRule rule = ScannerReport.AdHocRule.newBuilder()
  .setEngineId("eslint")
  .setRuleId("123")
  .setName("Foo")
  .setDescription("Description")
  .setSeverity(Constants.Severity.BLOCKER)
  .setType(ScannerReport.IssueType.BUG)
  .build();
 underTest.appendAdHocRule(rule);
 File file = underTest.getFileStructure().adHocRules();
 assertThat(file).exists().isFile();
 try (CloseableIterator<ScannerReport.AdHocRule> read = Protobuf.readStream(file, ScannerReport.AdHocRule.parser())) {
  assertThat(Iterators.size(read)).isEqualTo(1);
 }
}

相关文章