@VisibleForTesting public BinaryDiffResult diff(File actual, byte[] expected) throws IOException { return diff(actual.toPath(), expected); }
@VisibleForTesting public BinaryDiffResult diff(Path actual, byte[] expected) throws IOException { try (InputStream expectedStream = new ByteArrayInputStream(expected); InputStream actualStream = Files.newInputStream(actual)) { return diff(actualStream, expectedStream); } }
@VisibleForTesting public BinaryDiffResult diff(Path actual, byte[] expected) throws IOException { try (InputStream expectedStream = new ByteArrayInputStream(expected); InputStream actualStream = Files.newInputStream(actual)) { return diff(actualStream, expectedStream); } }
@VisibleForTesting public BinaryDiffResult diff(File actual, byte[] expected) throws IOException { return diff(actual.toPath(), expected); }
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 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); } }
BinaryDiffResult binaryDiffResult = binaryDiff.diff(actual, readAllBytes(expected.toPath())); 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 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); } }
/** * 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); } }
BinaryDiffResult binaryDiffResult = binaryDiff.diff(actual, readAllBytes(expected.toPath())); if (binaryDiffResult.hasNoDiff()) {
@VisibleForTesting public BinaryDiffResult diff(File actual, byte[] expected) throws IOException { InputStream expectedStream = new ByteArrayInputStream(expected); InputStream actualStream = null; boolean threw = true; try { actualStream = new FileInputStream(actual); BinaryDiffResult result = diff(actualStream, expectedStream); threw = false; return result; } finally { try { if (actualStream != null) actualStream.close(); } catch (IOException e) { // Only rethrow if it doesn't shadow an exception thrown from the inner try block if (!threw) throw e; } } }
/** * 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); } }