Java Examples for org.assertj.core.util.diff.Delta
The following java examples will help you to understand the usage of org.assertj.core.util.diff.Delta. These source code samples are taken from different open source projects.
Example 1
| Project: assertj-core-master File: Files.java View source code |
/**
* Asserts that the given files have same content. Adapted from <a
* href="http://junit-addons.sourceforge.net/junitx/framework/FileAssert.html" target="_blank">FileAssert</a> (from <a
* href="http://sourceforge.net/projects/junit-addons">JUnit-addons</a>.)
* @param info contains information about the assertion.
* @param actual the "actual" file.
* @param actualCharset {@link Charset} of the "actual" file.
* @param expected the "expected" file.
* @param expectedCharset {@link Charset} of the "actual" file.
* @throws NullPointerException if {@code expected} is {@code null}.
* @throws IllegalArgumentException if {@code expected} is not an existing file.
* @throws AssertionError if {@code actual} is {@code null}.
* @throws AssertionError if {@code actual} is not an existing file.
* @throws RuntimeIOException if an I/O error occurs.
* @throws AssertionError if the given files do not have same content.
*/
public void assertSameContentAs(AssertionInfo info, File actual, Charset actualCharset, File expected, Charset expectedCharset) {
verifyIsFile(expected);
assertIsFile(info, actual);
try {
List<Delta<String>> diffs = diff.diff(actual, actualCharset, expected, expectedCharset);
if (diffs.isEmpty())
return;
throw failures.failure(info, shouldHaveSameContent(actual, expected, diffs));
} catch (MalformedInputException e) {
try {
BinaryDiffResult binaryDiffResult = binaryDiff.diff(actual, readAllBytes(expected.toPath()));
if (binaryDiffResult.hasNoDiff()) {
throw e;
}
throw failures.failure(info, shouldHaveBinaryContent(actual, binaryDiffResult));
} catch (IOException ioe) {
throw new RuntimeIOException(format(UNABLE_TO_COMPARE_FILE_CONTENTS, actual, expected), ioe);
}
} catch (IOException e) {
throw new RuntimeIOException(format(UNABLE_TO_COMPARE_FILE_CONTENTS, actual, expected), e);
}
}Example 2
| Project: mapstruct-master File: JavaFileAssert.java View source code |
/**
* Verifies that the expected file has the same content as this Java file. The verification ignores
* the license header and the date/comments line from the {@code @Generated} annotation.
*
* @param expected the file that should be matched
*/
public void hasSameMapperContent(File expected) {
Charset charset = Charset.forName("UTF-8");
try {
List<Delta<String>> diffs = new ArrayList<Delta<String>>(this.diff.diff(actual, charset, expected, charset));
Iterator<Delta<String>> iterator = diffs.iterator();
while (iterator.hasNext()) {
Delta<String> delta = iterator.next();
if (ignoreDelta(delta)) {
iterator.remove();
}
}
if (!diffs.isEmpty()) {
throw Failures.instance().failure(info, ShouldHaveSameContent.shouldHaveSameContent(actual, expected, diffs));
}
} catch (IOException e) {
throw new RuntimeIOException(format("Unable to compare contents of files:<%s> and:<%s>", actual, expected), e);
}
}