/** * Asserts that the line count of the given {@code CharSequence} is equal to the expected one. * * @param info contains information about the assertion. * @param actual the given {@code CharSequence}. * @param expectedLineCount the expected line count of {@code actual}. * @throws AssertionError if the given {@code CharSequence} is {@code null}. * @throws AssertionError if the line count of the given {@code CharSequence} is different than the expected one. */ public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount) { assertNotNull(info, actual); LineNumberReader reader = new LineNumberReader(new StringReader(actual.toString())); try { while (reader.readLine() != null); } catch (IOException e) { throw new InputStreamsException(format("Unable to count lines in `%s`", actual), e); } checkLineCounts(actual, reader.getLineNumber(), expectedLineCount, info); }
/** * Asserts that the line count of the given {@code CharSequence} is equal to the expected one. * * @param info contains information about the assertion. * @param actual the given {@code CharSequence}. * @param expectedLineCount the expected line count of {@code actual}. * @throws AssertionError if the given {@code CharSequence} is {@code null}. * @throws AssertionError if the line count of the given {@code CharSequence} is different than the expected one. */ public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount) { assertNotNull(info, actual); LineNumberReader reader = new LineNumberReader(new StringReader(actual.toString())); try { while (reader.readLine() != null); } catch (IOException e) { throw new InputStreamsException(format("Unable to count lines in `%s`", actual), e); } checkLineCounts(actual, reader.getLineNumber(), expectedLineCount, info); }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * 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); } }
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); } }
/** * Asserts that the line count of the given {@code CharSequence} is equal to the expected one. * * @param info contains information about the assertion. * @param actual the given {@code CharSequence}. * @param expectedLineCount the expected line count of {@code actual}. * @throws AssertionError if the given {@code CharSequence} is {@code null}. * @throws AssertionError if the line count of the given {@code CharSequence} is different than the expected one. */ public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount) { assertNotNull(info, actual); LineNumberReader reader = new LineNumberReader(new StringReader(actual.toString())); try { while ((reader.readLine()) != null); } catch (IOException e) { String msg = format("Unable to count lines in `%s`", actual); throw new InputStreamsException(msg, e); } checkLineCounts(actual, reader.getLineNumber(), expectedLineCount, info); }
/** * 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); } }