@VisibleForTesting public BinaryDiffResult diff(InputStream actualStream, InputStream expectedStream) throws IOException { int index = 0; while (true) { int actual = actualStream.read(); int expected = expectedStream.read(); if (actual == -1 && expected == -1) return BinaryDiffResult.noDiff(); // reached end of both streams if (actual != expected) return new BinaryDiffResult(index, expected, actual); index += 1; } } }
/** * Builds a new instance. * * @param offset the offset at which the difference occurred. * @param expected the expected byte as an int in the range 0 to 255, or -1 for EOF. * @param actual the actual byte in the same format. */ public BinaryDiffResult(int offset, int expected, int actual) { this.offset = offset; this.expected = describe(expected); this.actual = describe(actual); }
public void assertHasBinaryContent(AssertionInfo info, Path actual, byte[] expected) { checkNotNull(expected, "The binary content to compare to should not be null"); assertIsReadable(info, actual); try { BinaryDiffResult diffResult = binaryDiff.diff(actual, expected); if (diffResult.hasNoDiff()) return; throw failures.failure(info, shouldHaveBinaryContent(actual, diffResult)); } catch (IOException e) { throw new UncheckedIOException(format("Unable to verify binary contents of path:<%s>", actual), e); } }
public static BinaryDiffResult noDiff() { return new BinaryDiffResult(EOF, 0, 0); }
public void assertHasBinaryContent(AssertionInfo info, Path actual, byte[] expected) { checkNotNull(expected, "The binary content to compare to should not be null"); assertIsReadable(info, actual); try { BinaryDiffResult diffResult = binaryDiff.diff(actual, expected); if (diffResult.hasNoDiff()) return; throw failures.failure(info, shouldHaveBinaryContent(actual, diffResult)); } catch (IOException e) { throw new UncheckedIOException(format("Unable to verify binary contents of path:<%s>", actual), e); } }
public static BinaryDiffResult noDiff() { return new BinaryDiffResult(EOF, 0, 0); }
@VisibleForTesting public BinaryDiffResult diff(InputStream actualStream, InputStream expectedStream) throws IOException { int index = 0; while (true) { int actual = actualStream.read(); int expected = expectedStream.read(); if (actual == -1 && expected == -1) return BinaryDiffResult.noDiff(); // reached end of both streams if (actual != expected) return new BinaryDiffResult(index, expected, actual); index += 1; } } }
if (binaryDiffResult.hasNoDiff()) {
public static BinaryDiffResult noDiff() { return new BinaryDiffResult(EOF, 0, 0); }
/** * Builds a new instance. * * @param offset the offset at which the difference occurred. * @param expected the expected byte as an int in the range 0 to 255, or -1 for EOF. * @param actual the actual byte in the same format. */ public BinaryDiffResult(int offset, int expected, int actual) { this.offset = offset; this.expected = describe(expected); this.actual = describe(actual); }
@VisibleForTesting public BinaryDiffResult diff(InputStream actualStream, InputStream expectedStream) throws IOException { int index = 0; while (true) { int actual = actualStream.read(); int expected = expectedStream.read(); if (actual == -1 && expected == -1) return BinaryDiffResult.noDiff(); // reached end of both streams if (actual != expected) return new BinaryDiffResult(index, expected, actual); index += 1; } } }
/** * Asserts that the given file has the given binary content. * @param info contains information about the assertion. * @param actual the "actual" file. * @param expected the "expected" binary content. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if {@code actual} is not an existing file. * @throws UncheckedIOException if an I/O error occurs. * @throws AssertionError if the file does not have the binary content. */ public void assertHasBinaryContent(AssertionInfo info, File actual, byte[] expected) { checkNotNull(expected, "The binary content to compare to should not be null"); assertIsFile(info, actual); try { BinaryDiffResult result = binaryDiff.diff(actual, expected); if (result.hasNoDiff()) return; throw failures.failure(info, shouldHaveBinaryContent(actual, result)); } catch (IOException e) { String msg = String.format("Unable to verify binary contents of file:<%s>", actual); throw new UncheckedIOException(msg, e); } }
/** * Builds a new instance. * * @param offset the offset at which the difference occurred. * @param expected the expected byte as an int in the range 0 to 255, or -1 for EOF. * @param actual the actual byte in the same format. */ public BinaryDiffResult(int offset, int expected, int actual) { this.offset = offset; this.expected = describe(expected); this.actual = describe(actual); }
/** * Asserts that the given file has the given binary content. * @param info contains information about the assertion. * @param actual the "actual" file. * @param expected the "expected" binary content. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if {@code actual} is not an existing file. * @throws UncheckedIOException if an I/O error occurs. * @throws AssertionError if the file does not have the binary content. */ public void assertHasBinaryContent(AssertionInfo info, File actual, byte[] expected) { checkNotNull(expected, "The binary content to compare to should not be null"); assertIsFile(info, actual); try { BinaryDiffResult result = binaryDiff.diff(actual, expected); if (result.hasNoDiff()) return; throw failures.failure(info, shouldHaveBinaryContent(actual, result)); } catch (IOException e) { String msg = String.format("Unable to verify binary contents of file:<%s>", actual); throw new UncheckedIOException(msg, e); } }
if (binaryDiffResult.hasNoDiff()) {
/** * Asserts that the given file has the given binary content. * @param info contains information about the assertion. * @param actual the "actual" file. * @param expected the "expected" binary content. * @throws NullPointerException if {@code expected} is {@code null}. * @throws AssertionError if {@code actual} is {@code null}. * @throws AssertionError if {@code actual} is not an existing file. * @throws FilesException if an I/O error occurs. * @throws AssertionError if the file does not have the binary content. */ public void assertHasBinaryContent(AssertionInfo info, File actual, byte[] expected) { if (expected == null) throw new NullPointerException("The binary content to compare to should not be null"); assertIsFile(info, actual); try { BinaryDiffResult result = binaryDiff.diff(actual, expected); if (result.hasNoDiff()) return; throw failures.failure(info, shouldHaveBinaryContent(actual, result)); } catch (IOException e) { String msg = String.format("Unable to verify binary contents of file:<%s>", actual); throw new FilesException(msg, e); } }