本文整理了Java中org.assertj.core.api.AbstractFileAssert.hasSameContentAs()
方法的一些代码示例,展示了AbstractFileAssert.hasSameContentAs()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractFileAssert.hasSameContentAs()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractFileAssert
类名称:AbstractFileAssert
方法名:hasSameContentAs
[英]Verifies that the content of the actual File is equal to the content of the given one. The charset to use when reading the actual file can be provided with #usingCharset(Charset) or #usingCharset(String) prior to calling this method; if not, the platform's default charset (as returned by Charset#defaultCharset()) will be used. Examples:
// use the default charset
File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();
File xFileClone = Files.write(Paths.get("xfile-clone.txt"), "The Truth Is Out There".getBytes()).toFile();
File xFileFrench = Files.write(Paths.get("xfile-french.txt"), "La Vérité Est Ailleurs".getBytes()).toFile();
// use UTF-8 charset
File xFileUTF8 = Files.write(Paths.get("xfile-clone.txt"), Arrays.asList("The Truth Is Out There"), StandardCharsets.UTF_8).toFile();
// The following assertion succeeds (default charset is used):
assertThat(xFile).hasSameContentAs(xFileClone);
// The following assertion succeeds (UTF-8 charset is used to read xFile):
assertThat(xFileUTF8).usingCharset("UTF-8").hasContent(xFileClone);
// The following assertion fails:
assertThat(xFile).hasSameContentAs(xFileFrench);
[中]验证实际文件的内容是否等于给定文件的内容。在调用此方法之前,可以为读取实际文件时使用的字符集提供#usingCharset(字符集)或#usingCharset(字符串);否则,将使用平台的默认字符集(由charset#defaultCharset()返回)。示例:
// use the default charset
File xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes()).toFile();
File xFileClone = Files.write(Paths.get("xfile-clone.txt"), "The Truth Is Out There".getBytes()).toFile();
File xFileFrench = Files.write(Paths.get("xfile-french.txt"), "La Vérité Est Ailleurs".getBytes()).toFile();
// use UTF-8 charset
File xFileUTF8 = Files.write(Paths.get("xfile-clone.txt"), Arrays.asList("The Truth Is Out There"), StandardCharsets.UTF_8).toFile();
// The following assertion succeeds (default charset is used):
assertThat(xFile).hasSameContentAs(xFileClone);
// The following assertion succeeds (UTF-8 charset is used to read xFile):
assertThat(xFileUTF8).usingCharset("UTF-8").hasContent(xFileClone);
// The following assertion fails:
assertThat(xFile).hasSameContentAs(xFileFrench);
代码示例来源:origin: org.assertj/assertj-core
return hasSameContentAs(expected);
代码示例来源:origin: apache/geode
/**
* Copies a {@code resource} to a {@code file} in {@code targetFolder}.
*
* @return the newly created file
*/
public static File createFileFromResource(final URL resource, final File targetFolder,
final String fileName) throws IOException, URISyntaxException {
File targetFile = new File(targetFolder, fileName);
IOUtils.copy(resource.openStream(), new FileOutputStream(targetFile));
assertThat(targetFile).hasSameContentAs(new File(resource.toURI()));
return targetFile;
}
}
代码示例来源:origin: joel-costigliola/assertj-core
return hasSameContentAs(expected);
代码示例来源: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 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: palantir/atlasdb
private void checkIfFilesAreTheSame(List<String> generatedTestTables) {
generatedTestTables.forEach(tableName -> {
String generatedFilePath =
String.format("com/palantir/atlasdb/table/description/generated/%s.java", tableName);
File expectedFile = new File(EXPECTED_FILES_FOLDER_PATH, generatedFilePath);
File actualFile = new File(testFolder.getRoot(), generatedFilePath);
assertThat(actualFile).hasSameContentAs(expectedFile);
});
}
内容来源于网络,如有侵权,请联系作者删除!