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

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

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

Assertions.contentOf介绍

[英]Loads the text content of a file with the default character set, so that it can be passed to #assertThat(String).

Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative with #assertThat(File).
[中]使用默认字符集加载文件的文本内容,以便将其传递给#assertThat(字符串)。
注意,这将在内存中加载整个文件;对于较大的文件,可能有一种更有效的替代方法#assertThat(文件)。

代码示例

代码示例来源:origin: org.assertj/assertj-core

/**
 * Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative
 * with {@link #assertThat(File)}.
 * </p>
 *
 * @param file the file.
 * @param charsetName the name of the character set to use.
 * @return the content of the file.
 * @throws IllegalArgumentException if the given character set is not supported on this platform.
 * @throws UncheckedIOException if an I/O exception occurs.
 */
default String contentOf(final File file, final String charsetName) {
 return Assertions.contentOf(file, charsetName);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Loads the text content of a file with the default character set, so that it can be passed to
 * {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative
 * with {@link #assertThat(File)}.
 * </p>
 *
 * @param file the file.
 * @return the content of the file.
 * @throws UncheckedIOException if an I/O exception occurs.
 */
default String contentOf(final File file) {
 return Assertions.contentOf(file);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Loads the text content of a URL with the default character set, so that it can be passed to
 * {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files.
 * </p>
 *
 * @param url the URL.
 * @return the content of the file.
 * @throws UncheckedIOException if an I/O exception occurs.
 * @since 3.9.0
 */
default String contentOf(URL url) {
 return Assertions.contentOf(url);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative
 * with {@link #assertThat(File)}.
 * </p>
 *
 * @param file the file.
 * @param charset the character set to use.
 * @return the content of the file.
 * @throws NullPointerException if the given charset is {@code null}.
 * @throws UncheckedIOException if an I/O exception occurs.
 */
default String contentOf(final File file, final Charset charset) {
 return Assertions.contentOf(file, charset);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Loads the text content of a URL, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire contents in memory.
 * </p>
 *
 * @param url the URL.
 * @param charset the character set to use.
 * @return the content of the URL.
 * @throws NullPointerException if the given charset is {@code null}.
 * @throws UncheckedIOException if an I/O exception occurs.
 * @since 3.9.0
 */
default String contentOf(URL url, Charset charset) {
 return Assertions.contentOf(url, charset);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Loads the text content of a URL, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire contents in memory.
 * </p>
 *
 * @param url the URL.
 * @param charsetName the name of the character set to use.
 * @return the content of the URL.
 * @throws IllegalArgumentException if the given character set is not supported on this platform.
 * @throws UncheckedIOException if an I/O exception occurs.
 * @since 3.9.0
 */
default String contentOf(URL url, String charsetName) {
 return Assertions.contentOf(url, charsetName);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Loads the text content of a URL with the default character set, so that it can be passed to
 * {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files.
 * </p>
 *
 * @param url the URL.
 * @return the content of the file.
 * @throws UncheckedIOException if an I/O exception occurs.
 * @since 3.9.0
 */
default String contentOf(URL url) {
 return Assertions.contentOf(url);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Loads the text content of a URL, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire contents in memory.
 * </p>
 *
 * @param url the URL.
 * @param charsetName the name of the character set to use.
 * @return the content of the URL.
 * @throws IllegalArgumentException if the given character set is not supported on this platform.
 * @throws UncheckedIOException if an I/O exception occurs.
 * @since 3.9.0
 */
default String contentOf(URL url, String charsetName) {
 return Assertions.contentOf(url, charsetName);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Loads the text content of a file with the default character set, so that it can be passed to
 * {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative
 * with {@link #assertThat(File)}.
 * </p>
 *
 * @param file the file.
 * @return the content of the file.
 * @throws UncheckedIOException if an I/O exception occurs.
 */
default String contentOf(final File file) {
 return Assertions.contentOf(file);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative
 * with {@link #assertThat(File)}.
 * </p>
 *
 * @param file the file.
 * @param charsetName the name of the character set to use.
 * @return the content of the file.
 * @throws IllegalArgumentException if the given character set is not supported on this platform.
 * @throws UncheckedIOException if an I/O exception occurs.
 */
default String contentOf(final File file, final String charsetName) {
 return Assertions.contentOf(file, charsetName);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Loads the text content of a URL, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire contents in memory.
 * </p>
 *
 * @param url the URL.
 * @param charset the character set to use.
 * @return the content of the URL.
 * @throws NullPointerException if the given charset is {@code null}.
 * @throws UncheckedIOException if an I/O exception occurs.
 * @since 3.9.0
 */
default String contentOf(URL url, Charset charset) {
 return Assertions.contentOf(url, charset);
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Loads the text content of a file, so that it can be passed to {@link #assertThat(String)}.
 * <p>
 * Note that this will load the entire file in memory; for larger files, there might be a more efficient alternative
 * with {@link #assertThat(File)}.
 * </p>
 *
 * @param file the file.
 * @param charset the character set to use.
 * @return the content of the file.
 * @throws NullPointerException if the given charset is {@code null}.
 * @throws UncheckedIOException if an I/O exception occurs.
 */
default String contentOf(final File file, final Charset charset) {
 return Assertions.contentOf(file, charset);
}

代码示例来源:origin: org.assertj/assertj-core

/**
 * Verifies that the actual {@code CharSequence} is equal to the content of the given file.
 * <p>
 * This is an handy shortcut that calls : {@code isXmlEqualTo(contentOf(xmlFile))}
 * </p>
 * Example :
 * <pre><code class='java'> // You can easily compare your XML String to the content of an XML file, whatever how formatted they are.
 * String oneLineXml = &quot;&lt;rings&gt;&lt;bearer&gt;&lt;name&gt;Frodo&lt;/name&gt;&lt;ring&gt;&lt;name&gt;one ring&lt;/name&gt;&lt;createdBy&gt;Sauron&lt;/createdBy&gt;&lt;/ring&gt;&lt;/bearer&gt;&lt;/rings&gt;&quot;;
 * assertThat(oneLineXml).isXmlEqualToContentOf(new File(&quot;src/test/resources/formatted.xml&quot;));</code></pre>
 *
 * @param xmlFile the file to read the expected XML String to compare with actual {@code CharSequence}
 * @return {@code this} assertion object to chain other assertions.
 * @throws NullPointerException if the given {@code File} is {@code null}.
 * @throws AssertionError if the actual {@code CharSequence} is {@code null} or is not the same XML as the content of
 *           given {@code File}.
 */
public SELF isXmlEqualToContentOf(File xmlFile) {
 isXmlEqualTo(contentOf(xmlFile));
 return myself;
}

代码示例来源:origin: joel-costigliola/assertj-core

/**
 * Verifies that the actual {@code CharSequence} is equal to the content of the given file.
 * <p>
 * This is an handy shortcut that calls : {@code isXmlEqualTo(contentOf(xmlFile))}
 * </p>
 * Example :
 * <pre><code class='java'> // You can easily compare your XML String to the content of an XML file, whatever how formatted they are.
 * String oneLineXml = &quot;&lt;rings&gt;&lt;bearer&gt;&lt;name&gt;Frodo&lt;/name&gt;&lt;ring&gt;&lt;name&gt;one ring&lt;/name&gt;&lt;createdBy&gt;Sauron&lt;/createdBy&gt;&lt;/ring&gt;&lt;/bearer&gt;&lt;/rings&gt;&quot;;
 * assertThat(oneLineXml).isXmlEqualToContentOf(new File(&quot;src/test/resources/formatted.xml&quot;));</code></pre>
 *
 * @param xmlFile the file to read the expected XML String to compare with actual {@code CharSequence}
 * @return {@code this} assertion object to chain other assertions.
 * @throws NullPointerException if the given {@code File} is {@code null}.
 * @throws AssertionError if the actual {@code CharSequence} is {@code null} or is not the same XML as the content of
 *           given {@code File}.
 */
public SELF isXmlEqualToContentOf(File xmlFile) {
 isXmlEqualTo(contentOf(xmlFile));
 return myself;
}

代码示例来源:origin: org.assertj/assertj-core-java8

/**
 * Delegate call to {@link org.assertj.core.api.Assertions#contentOf(File)}
 */
default public String contentOf(final File actual) {
 return Assertions.contentOf(actual);
}

代码示例来源:origin: org.assertj/assertj-core-java8

/**
 * Delegate call to {@link org.assertj.core.api.Assertions#contentOf(File,String)}
 */
default public String contentOf(final File file, final String charsetName) {
 return Assertions.contentOf(file, charsetName);
}

代码示例来源:origin: org.assertj/assertj-core-java8

/**
 * Delegate call to {@link org.assertj.core.api.Assertions#contentOf(File,Charset)}
 */
default public String contentOf(final File file, final Charset charset) {
 return Assertions.contentOf(file, charset);
}

代码示例来源:origin: zanata/zanata-platform

private String contentOfResource(String name) {
  URL resource = getClass().getResource(name);
  assertThat(resource).as("missing test resource").isNotNull();
  return contentOf(resource, UTF_8);
}

代码示例来源:origin: metafacture/metafacture-core

@Test
public void shouldWriteBytesToFile() throws IOException {
  File outputFile = tempFolder.newFile();
  byteStreamFileWriter.setFileNameSupplier(() -> outputFile);
  byteStreamFileWriter.process(SOME_DATA.getBytes(StandardCharsets.UTF_8));
  byteStreamFileWriter.closeStream();
  assertThat(outputFile).isFile();
  assertThat(contentOf(outputFile)).isEqualTo(SOME_DATA);
}

代码示例来源:origin: metafacture/metafacture-core

@Test
public void shouldOverwriteExistingFilesByDefault() throws IOException {
  File outputFile = tempFolder.newFile();
  byteStreamFileWriter.setFileNameSupplier(() -> outputFile);
  byteStreamFileWriter.process(SOME_DATA.getBytes(StandardCharsets.UTF_8));
  byteStreamFileWriter.resetStream();
  byteStreamFileWriter.process(SOME_MORE_DATA.getBytes(StandardCharsets.UTF_8));
  byteStreamFileWriter.closeStream();
  assertThat(outputFile).isFile();
  assertThat(contentOf(outputFile)).isEqualTo(SOME_MORE_DATA);
}

相关文章