Search in sources :

Example 11 with Delta

use of org.assertj.core.util.diff.Delta in project mapstruct by mapstruct.

the class JavaFileAssert method hasSameMapperContent.

/**
 * 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);
    }
}
Also used : RuntimeIOException(org.assertj.core.api.exception.RuntimeIOException) Delta(org.assertj.core.util.diff.Delta) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) IOException(java.io.IOException) RuntimeIOException(org.assertj.core.api.exception.RuntimeIOException)

Aggregations

Delta (org.assertj.core.util.diff.Delta)11 Test (org.junit.Test)6 IOException (java.io.IOException)5 AssertionInfo (org.assertj.core.api.AssertionInfo)5 UncheckedIOException (java.io.UncheckedIOException)4 FilesBaseTest (org.assertj.core.internal.FilesBaseTest)2 Charset (java.nio.charset.Charset)1 MalformedInputException (java.nio.charset.MalformedInputException)1 ArrayList (java.util.ArrayList)1 RuntimeIOException (org.assertj.core.api.exception.RuntimeIOException)1 TextDescription (org.assertj.core.description.TextDescription)1 BinaryDiffResult (org.assertj.core.internal.BinaryDiffResult)1 InputStreamsBaseTest (org.assertj.core.internal.InputStreamsBaseTest)1 PathsBaseTest (org.assertj.core.internal.PathsBaseTest)1