本文整理了Java中org.assertj.core.api.AbstractPathAssert.hasContent()
方法的一些代码示例,展示了AbstractPathAssert.hasContent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractPathAssert.hasContent()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractPathAssert
类名称:AbstractPathAssert
方法名:hasContent
[英]Verifies that the text content of the actual Path (which must be a readable file) is exactly equal to the given one.
The charset to use when reading the actual path should 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
Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());
// The following assertion succeeds (default charset is used):
assertThat(xFile).hasContent("The Truth Is Out There");
// The following assertion fails:
assertThat(xFile).hasContent("La Vérité Est Ailleurs");
// using a specific charset
Charset turkishCharset = Charset.forName("windows-1254");
Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek Başka bir yerde mi"), turkishCharset);
// The following assertion succeeds:
assertThat(xFileTurkish).usingCharset(turkishCharset).hasContent("Gerçek Başka bir yerde mi");
// The following assertion fails ... unless you are in Turkey ;-):
assertThat(xFileTurkish).hasContent("Gerçek Başka bir yerde mi");
[中]验证实际路径(必须是可读文件)的文本内容是否与给定路径完全相同。
在调用此方法之前,应为读取实际路径时使用的字符集提供#usingCharset(字符集)或#usingCharset(字符串);否则,将使用平台的默认字符集(由charset#defaultCharset()返回)。示例:
// use the default charset
Path xFile = Files.write(Paths.get("xfile.txt"), "The Truth Is Out There".getBytes());
// The following assertion succeeds (default charset is used):
assertThat(xFile).hasContent("The Truth Is Out There");
// The following assertion fails:
assertThat(xFile).hasContent("La Vérité Est Ailleurs");
// using a specific charset
Charset turkishCharset = Charset.forName("windows-1254");
Path xFileTurkish = Files.write(Paths.get("xfile.turk"), Collections.singleton("Gerçek Başka bir yerde mi"), turkishCharset);
// The following assertion succeeds:
assertThat(xFileTurkish).usingCharset(turkishCharset).hasContent("Gerçek Başka bir yerde mi");
// The following assertion fails ... unless you are in Turkey ;-):
assertThat(xFileTurkish).hasContent("Gerçek Başka bir yerde mi");
代码示例来源: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: allure-framework/allure2
@Test
public void shouldLoadStaticOnlyPlugin() throws Exception {
final Path pluginFolder = folder.newFolder().toPath();
add(pluginFolder, "static-file.txt", "static/some-file");
add(pluginFolder, "dummy-plugin2.yml", "allure-plugin.yml");
final Optional<Plugin> loaded = pluginLoader.loadPlugin(getClass().getClassLoader(), pluginFolder);
assertThat(loaded)
.isPresent();
final Plugin plugin = loaded.get();
assertThat(plugin.getConfig())
.isNotNull()
.hasFieldOrPropertyWithValue("id", "dummy");
assertThat(plugin.getExtensions())
.isNotNull()
.isEmpty();
final Path unpack = folder.newFolder().toPath();
plugin.unpackReportStatic(unpack);
assertThat(unpack.resolve("some-file"))
.isRegularFile()
.hasContent("ho-ho-ho");
}
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldAddLogAsAttachment() throws Exception {
final Attachment hey = new Attachment().setUid("some-uid");
when(visitor.visitAttachmentFile(any())).thenReturn(hey);
process(
"junitdata/TEST-test.SampleTest.xml", "TEST-test.SampleTest.xml",
"junitdata/test.SampleTest.txt", "test.SampleTest.txt"
);
final ArgumentCaptor<Path> attachmentCaptor = ArgumentCaptor.forClass(Path.class);
verify(visitor, times(1)).visitAttachmentFile(attachmentCaptor.capture());
assertThat(attachmentCaptor.getValue())
.isRegularFile()
.hasContent("some-test-log");
final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class);
verify(visitor, times(1)).visitTestResult(captor.capture());
final StageResult testStage = captor.getValue().getTestStage();
assertThat(testStage)
.describedAs("Should create a test stage")
.isNotNull();
assertThat(testStage.getAttachments())
.describedAs("Should add an attachment")
.hasSize(1)
.describedAs("Attachment should has right uid and name")
.extracting(Attachment::getName, Attachment::getUid)
.containsExactly(Tuple.tuple("System out", "some-uid"));
}
代码示例来源:origin: hcoles/pitest
@Test
public void shouldWriteMutantDetailsToDisk() {
final Collection<MutationDetails> mutations = executeFor(VeryMutable.class);
final MutationDetails firstMutant = mutations.iterator().next();
final Path shouldBeCreated = mutantBasePath(VeryMutable.class,0).resolve("details.txt");
assertThat(shouldBeCreated).hasContent(firstMutant.toString());
}
代码示例来源:origin: com.pragmaticobjects.oo.atom/atom-basis
@Override
public final void check() throws Exception {
Path tempDirectory = Files.createTempDirectory("javapoetsource-test");
source.saveIn(tempDirectory);
Assertions.assertThat(tempDirectory.resolve(expectedModule)).isRegularFile();
Assertions.assertThat(tempDirectory.resolve(expectedModule)).hasContent(expectedCode);
}
}
代码示例来源:origin: SonarSource/sonarlint-intellij
@Test
public void testContains() throws IOException {
store.write("mykey", "myvalue");
assertThat(getPath("mykey")).hasContent("myvalue");
assertThat(store.contains("mykey")).isTrue();
assertThat(store.contains("random")).isFalse();
}
代码示例来源:origin: SonarSource/sonarlint-intellij
@Test
public void testWrite() throws IOException {
store.write("mykey", "myvalue");
assertThat(getPath("mykey")).hasContent("myvalue");
verify(index).save("mykey", getPath("mykey"));
assertThat(store.read("mykey").get()).isEqualTo("myvalue");
}
代码示例来源:origin: SonarSource/sonarlint-intellij
@Test
public void testDelete() throws IOException {
store.write("mykey", "myvalue");
assertThat(getPath("mykey")).hasContent("myvalue");
store.delete("mykey");
assertThat(store.read("mykey").isPresent()).isFalse();
assertThat(getPath("mykey")).doesNotExist();
verify(index).delete("mykey");
}
代码示例来源:origin: zanata/zanata-platform
@Test
public void writeTranslatedAndApproved() throws Exception {
Resource srcDoc = sourceDocWithTwoEntries();
TranslationsResource doc = targetDocumentWithOneTranslatedOneApproved();
Path file = createTempFile(null, null);
try {
boolean approvedOnly = false;
PropWriter.writeTranslationsFile(new TranslatedDoc(srcDoc, doc, localeId),
file.toFile(), PropWriter.CHARSET.UTF8, false, approvedOnly);
assertThat(file).hasContent("hello=bon jour\ngoodbye=au revoir\n");
} finally {
deleteIfExists(file);
}
}
代码示例来源:origin: zanata/zanata-platform
@Test
public void writeApprovedOnlyWithSkeleton() throws Exception {
Resource srcDoc = sourceDocWithTwoEntries();
TranslationsResource doc = targetDocumentWithOneTranslatedOneApproved();
Path file = createTempFile(null, null);
try {
boolean approvedOnly = true;
PropWriter.writeTranslationsFile(new TranslatedDoc(srcDoc, doc, localeId),
file.toFile(), PropWriter.CHARSET.UTF8, true, approvedOnly);
// hello is only Translated, so it should be a skeleton
assertThat(file).hasContent("hello=\ngoodbye=au revoir\n");
} finally {
deleteIfExists(file);
}
}
代码示例来源:origin: zanata/zanata-platform
@Test
public void writeApprovedOnly() throws Exception {
Resource srcDoc = sourceDocWithTwoEntries();
TranslationsResource doc = targetDocumentWithOneTranslatedOneApproved();
Path file = createTempFile(null, null);
try {
boolean approvedOnly = true;
PropWriter.writeTranslationsFile(new TranslatedDoc(srcDoc, doc, localeId),
file.toFile(), PropWriter.CHARSET.UTF8, false, approvedOnly);
// hello is only Translated, so it should be left out
assertThat(file).hasContent("goodbye=au revoir\n");
} finally {
deleteIfExists(file);
}
}
内容来源于网络,如有侵权,请联系作者删除!