/** * Verifies that the content of the actual {@code InputStream} is equal to the given {@code String}. * <p> * Example: * <pre><code class='java'> // assertion will pass * assertThat(new ByteArrayInputStream("a".getBytes())).hasContent("a"); * * // assertions will fail * assertThat(new ByteArrayInputStream("a".getBytes())).hasContent(""); * assertThat(new ByteArrayInputStream("a".getBytes())).hasContent("ab");</code></pre> * * @param expected the given {@code String} to compare the actual {@code InputStream} to. * @return {@code this} assertion object. * @throws NullPointerException if the given {@code String} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the content of the actual {@code InputStream} is not equal to the given {@code String}. * @throws InputStreamsException if an I/O error occurs. * @since 3.11.0 */ public SELF hasContent(String expected) { inputStreams.assertHasContent(info, actual, expected); return myself; }
/** * Verifies that the tested {@link InputStream} digest (calculated with the specified {@link MessageDigest}) is equal to the given one. * <p> * Examples: * <pre><code class="java"> // assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar * InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); * * // The following assertions succeed: * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44}); * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25}); * * // The following assertions fail: * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes()); * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f".getBytes());</code></pre> * * @param digest the MessageDigest used to calculate the digests. * @param expected the expected binary content to compare the actual {@code InputStream}'s digest to. * @return {@code this} assertion object. * @throws NullPointerException if the given algorithm is {@code null}. * @throws NullPointerException if the given digest is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is not readable. * @throws InputStreamsException if an I/O error occurs. * @throws AssertionError if the content of the tested {@code InputStream}'s digest is not equal to the given one. * @since 3.11.0 */ public SELF hasDigest(MessageDigest digest, byte[] expected) { inputStreams.assertHasDigest(info, actual, digest, expected); return myself; }
/** * Verifies that the content of the actual {@code InputStream} is equal to the content of the given one. * <p> * Example: * <pre><code class='java'> // assertion will pass * assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa})); * * // assertions will fail * assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {})); * assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa, 0xc, 0xd}));</code></pre> * * @param expected the given {@code InputStream} to compare the actual {@code InputStream} to. * @return {@code this} assertion object. * @throws NullPointerException if the given {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one. * @throws InputStreamsException if an I/O error occurs. */ public SELF hasSameContentAs(InputStream expected) { inputStreams.assertSameContentAs(info, actual, expected); return myself; }
/** * Asserts that the given InputStreams have same content. * * @param info contains information about the assertion. * @param actual the "actual" InputStream. * @param expected the "expected" InputStream. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the given InputStreams do not have same content. * @throws InputStreamsException if an I/O error occurs. */ public void assertSameContentAs(AssertionInfo info, InputStream actual, InputStream expected) { checkNotNull(expected, "The InputStream to compare to should not be null"); assertNotNull(info, actual); try { List<Delta<String>> diffs = diff.diff(actual, expected); if (diffs.isEmpty()) return; throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs)); } catch (IOException e) { String msg = format("Unable to compare contents of InputStreams:%n <%s>%nand:%n <%s>", actual, expected); throw new InputStreamsException(msg, e); } }
/** * Verifies that the content of the actual {@code InputStream} is equal to the content of the given one. * * @param expected the given {@code InputStream} to compare the actual {@code InputStream} to. * @return {@code this} assertion object. * @throws NullPointerException if the given {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one. * @throws InputStreamsException if an I/O error occurs. */ public S hasContentEqualTo(InputStream expected) { inputStreams.assertEqualContent(info, actual, expected); return myself; } }
/** * Asserts that the given InputStream has the same content as the given String. * * @param info contains information about the assertion. * @param actual the actual InputStream. * @param expected the expected String. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the given InputStream does not have the same content as the given String. * @throws InputStreamsException if an I/O error occurs. */ public void assertHasContent(AssertionInfo info, InputStream actual, String expected) { checkNotNull(expected, "The String to compare to should not be null"); assertNotNull(info, actual); try { List<Delta<String>> diffs = diff.diff(actual, expected); if (diffs.isEmpty()) return; throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs)); } catch (IOException e) { String msg = format("Unable to compare contents of InputStream:%n <%s>%nand String:%n <%s>", actual, expected); throw new InputStreamsException(msg, e); } }
public void assertHasDigest(AssertionInfo info, InputStream actual, MessageDigest digest, byte[] expected) { checkNotNull(digest, "The message digest algorithm should not be null"); checkNotNull(expected, "The binary representation of digest to compare to should not be null"); assertNotNull(info, actual); try { DigestDiff diff = digestDiff(actual, digest, expected); if (diff.digestsDiffer()) throw failures.failure(info, shouldHaveDigest(actual, diff)); } catch (IOException e) { String msg = format("Unable to calculate digest of InputStream:%n <%s>", actual); throw new InputStreamsException(msg, e); } }
/** * Verifies that the tested {@link InputStream} digest (calculated with the specified {@link MessageDigest}) is equal to the given one. * <p> * Examples: * <pre><code class="java"> // assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar * InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); * * // The following assertions succeed: * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "5c5ae45b58f12023817abe492447cdc7912c1a2c"); * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "dcb3015cd28447644c810af352832c19"); * * // The following assertions fail: * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad"); * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f");</code></pre> * * @param digest the MessageDigest used to calculate the digests. * @param expected the expected binary content to compare the actual {@code InputStream}'s digest to. * @return {@code this} assertion object. * @throws NullPointerException if the given algorithm is {@code null}. * @throws NullPointerException if the given digest is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is not readable. * @throws InputStreamsException if an I/O error occurs. * @throws AssertionError if the content of the tested {@code InputStream}'s digest is not equal to the given one. * @since 3.11.0 */ public SELF hasDigest(MessageDigest digest, String expected) { inputStreams.assertHasDigest(info, actual, digest, expected); return myself; }
/** * Verifies that the content of the actual {@code InputStream} is equal to the content of the given one. * <p> * Example: * <pre><code class='java'> // assertion will pass * assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa})); * * // assertions will fail * assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {})); * assertThat(new ByteArrayInputStream(new byte[] {0xa})).hasSameContentAs(new ByteArrayInputStream(new byte[] {0xa, 0xc, 0xd}));</code></pre> * * @param expected the given {@code InputStream} to compare the actual {@code InputStream} to. * @return {@code this} assertion object. * @throws NullPointerException if the given {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one. * @throws InputStreamsException if an I/O error occurs. */ public SELF hasSameContentAs(InputStream expected) { inputStreams.assertSameContentAs(info, actual, expected); return myself; }
/** * Verifies that the content of the actual {@code InputStream} is equal to the given {@code String}. * <p> * Example: * <pre><code class='java'> // assertion will pass * assertThat(new ByteArrayInputStream("a".getBytes())).hasContent("a"); * * // assertions will fail * assertThat(new ByteArrayInputStream("a".getBytes())).hasContent(""); * assertThat(new ByteArrayInputStream("a".getBytes())).hasContent("ab");</code></pre> * * @param expected the given {@code String} to compare the actual {@code InputStream} to. * @return {@code this} assertion object. * @throws NullPointerException if the given {@code String} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the content of the actual {@code InputStream} is not equal to the given {@code String}. * @throws InputStreamsException if an I/O error occurs. * @since 3.11.0 */ public SELF hasContent(String expected) { inputStreams.assertHasContent(info, actual, expected); return myself; }
/** * Asserts that the given InputStreams have same content. * * @param info contains information about the assertion. * @param actual the "actual" InputStream. * @param expected the "expected" InputStream. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the given InputStreams do not have same content. * @throws InputStreamsException if an I/O error occurs. */ public void assertSameContentAs(AssertionInfo info, InputStream actual, InputStream expected) { checkNotNull(expected, "The InputStream to compare to should not be null"); assertNotNull(info, actual); try { List<Delta<String>> diffs = diff.diff(actual, expected); if (diffs.isEmpty()) return; throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs)); } catch (IOException e) { String msg = format("Unable to compare contents of InputStreams:%n <%s>%nand:%n <%s>", actual, expected); throw new InputStreamsException(msg, e); } }
/** * Verifies that the tested {@link InputStream} digest (calculated with the specified algorithm) is equal to the given one. * <p> * Examples: * <pre><code class="java"> // assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar * InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); * * // The following assertion succeeds: * assertThat(tested).hasDigest("SHA1", new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44}); * assertThat(tested).hasDigest("MD5", new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25}); * * // The following assertion fails: * assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes()); * assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f".getBytes()); </code></pre> * * @param algorithm the algorithm used to calculate the digests. * @param expected the expected binary content to compare the actual {@code InputStream}'s content to. * @return {@code this} assertion object. * @throws NullPointerException if the given algorithm is {@code null}. * @throws NullPointerException if the given digest is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is not readable. * @throws InputStreamsException if an I/O error occurs. * @throws AssertionError if the content of the tested {@code InputStream}'s digest is not equal to the given one. * @since 3.11.0 */ public SELF hasDigest(String algorithm, byte[] expected) { inputStreams.assertHasDigest(info, actual, algorithm, expected); return myself; }
/** * Verifies that the content of the actual {@code InputStream} is equal to the content of the given one. * * @param expected the given {@code InputStream} to compare the actual {@code InputStream} to. * @return {@code this} assertion object. * @throws NullPointerException if the given {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one. * @throws InputStreamsException if an I/O error occurs. * * @deprecated use {@link #hasSameContentAs(InputStream)} instead */ @Deprecated public SELF hasContentEqualTo(InputStream expected) { inputStreams.assertSameContentAs(info, actual, expected); return myself; }
/** * Asserts that the given InputStream has the same content as the given String. * * @param info contains information about the assertion. * @param actual the actual InputStream. * @param expected the expected String. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the given InputStream does not have the same content as the given String. * @throws InputStreamsException if an I/O error occurs. */ public void assertHasContent(AssertionInfo info, InputStream actual, String expected) { checkNotNull(expected, "The String to compare to should not be null"); assertNotNull(info, actual); try { List<Delta<String>> diffs = diff.diff(actual, expected); if (diffs.isEmpty()) return; throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs)); } catch (IOException e) { String msg = format("Unable to compare contents of InputStream:%n <%s>%nand String:%n <%s>", actual, expected); throw new InputStreamsException(msg, e); } }
inputStreams.assertHasDigest(info, actual, algorithm, expected); return myself;
/** * Verifies that the content of the actual {@code InputStream} is equal to the content of the given one. * * @param expected the given {@code InputStream} to compare the actual {@code InputStream} to. * @return {@code this} assertion object. * @throws NullPointerException if the given {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the content of the actual {@code InputStream} is not equal to the content of the given one. * @throws InputStreamsException if an I/O error occurs. * * @deprecated use {@link #hasSameContentAs(InputStream)} instead */ @Deprecated public SELF hasContentEqualTo(InputStream expected) { inputStreams.assertSameContentAs(info, actual, expected); return myself; }
public void assertHasDigest(AssertionInfo info, InputStream actual, MessageDigest digest, byte[] expected) { checkNotNull(digest, "The message digest algorithm should not be null"); checkNotNull(expected, "The binary representation of digest to compare to should not be null"); assertNotNull(info, actual); try { DigestDiff diff = digestDiff(actual, digest, expected); if (diff.digestsDiffer()) throw failures.failure(info, shouldHaveDigest(actual, diff)); } catch (IOException e) { String msg = format("Unable to calculate digest of InputStream:%n <%s>", actual); throw new InputStreamsException(msg, e); } }
/** * Verifies that the tested {@link InputStream} digest (calculated with the specified {@link MessageDigest}) is equal to the given one. * <p> * Examples: * <pre><code class="java"> // assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar * InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); * * // The following assertions succeed: * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44}); * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25}); * * // The following assertions fail: * assertThat(tested).hasDigest(MessageDigest.getInstance("SHA1"), "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes()); * assertThat(tested).hasDigest(MessageDigest.getInstance("MD5"), "3735dff8e1f9df0492a34ef075205b8f".getBytes());</code></pre> * * @param digest the MessageDigest used to calculate the digests. * @param expected the expected binary content to compare the actual {@code InputStream}'s digest to. * @return {@code this} assertion object. * @throws NullPointerException if the given algorithm is {@code null}. * @throws NullPointerException if the given digest is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is not readable. * @throws InputStreamsException if an I/O error occurs. * @throws AssertionError if the content of the tested {@code InputStream}'s digest is not equal to the given one. * @since 3.11.0 */ public SELF hasDigest(MessageDigest digest, byte[] expected) { inputStreams.assertHasDigest(info, actual, digest, expected); return myself; }
/** * Asserts that the given InputStreams have equal content. * * @param info contains information about the assertion. * @param actual the "actual" InputStream. * @param expected the "expected" InputStream. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if the given InputStreams do not have equal content. * @throws InputStreamsException if an I/O error occurs. */ public void assertEqualContent(AssertionInfo info, InputStream actual, InputStream expected) { if (expected == null) throw new NullPointerException("The InputStream to compare to should not be null"); assertNotNull(info, actual); try { List<String> diffs = diff.diff(actual, expected); if (diffs.isEmpty()) return; throw failures.failure(info, shouldHaveEqualContent(actual, expected, diffs)); } catch (IOException e) { String msg = format("Unable to compare contents of InputStreams:\n <%s>\nand:\n <%s>", actual, expected); throw new InputStreamsException(msg, e); } }
/** * Verifies that the tested {@link InputStream} digest (calculated with the specified algorithm) is equal to the given one. * <p> * Examples: * <pre><code class="java"> // assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2/org/assertj/assertj-core/2.9.0/assertj-core-2.9.0.jar * InputStream tested = new FileInputStream(new File("assertj-core-2.9.0.jar")); * * // The following assertion succeeds: * assertThat(tested).hasDigest("SHA1", new byte[]{92, 90, -28, 91, 88, -15, 32, 35, -127, 122, -66, 73, 36, 71, -51, -57, -111, 44, 26, 44}); * assertThat(tested).hasDigest("MD5", new byte[]{-36, -77, 1, 92, -46, -124, 71, 100, 76, -127, 10, -13, 82, -125, 44, 25}); * * // The following assertion fails: * assertThat(tested).hasDigest("SHA1", "93b9ced2ee5b3f0f4c8e640e77470dab031d4cad".getBytes()); * assertThat(tested).hasDigest("MD5", "3735dff8e1f9df0492a34ef075205b8f".getBytes()); </code></pre> * * @param algorithm the algorithm used to calculate the digests. * @param expected the expected binary content to compare the actual {@code InputStream}'s content to. * @return {@code this} assertion object. * @throws NullPointerException if the given algorithm is {@code null}. * @throws NullPointerException if the given digest is {@code null}. * @throws AssertionError if the actual {@code InputStream} is {@code null}. * @throws AssertionError if the actual {@code InputStream} is not readable. * @throws InputStreamsException if an I/O error occurs. * @throws AssertionError if the content of the tested {@code InputStream}'s digest is not equal to the given one. * @since 3.11.0 */ public SELF hasDigest(String algorithm, byte[] expected) { inputStreams.assertHasDigest(info, actual, algorithm, expected); return myself; }