Search in sources :

Example 6 with Delta

use of org.assertj.core.util.diff.Delta in project assertj-core by joel-costigliola.

the class Files_assertHasContent_Test method should_fail_if_file_does_not_have_expected_text_content.

@Test
public void should_fail_if_file_does_not_have_expected_text_content() throws IOException {
    List<Delta<String>> diffs = Lists.newArrayList(delta);
    when(diff.diff(actual, expected, charset)).thenReturn(diffs);
    AssertionInfo info = someInfo();
    try {
        files.assertHasContent(info, actual, expected, charset);
    } catch (AssertionError e) {
        verify(failures).failure(info, shouldHaveContent(actual, charset, diffs));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) Delta(org.assertj.core.util.diff.Delta) Test(org.junit.Test) FilesBaseTest(org.assertj.core.internal.FilesBaseTest)

Example 7 with Delta

use of org.assertj.core.util.diff.Delta in project assertj-core by joel-costigliola.

the class Paths method assertHasContent.

public void assertHasContent(final AssertionInfo info, Path actual, String expected, Charset charset) {
    checkNotNull(expected, "The text to compare to should not be null");
    assertIsReadable(info, actual);
    try {
        List<Delta<String>> diffs = diff.diff(actual, expected, charset);
        if (diffs.isEmpty())
            return;
        throw failures.failure(info, shouldHaveContent(actual, charset, diffs));
    } catch (IOException e) {
        throw new UncheckedIOException(format("Unable to verify text contents of path:<%s>", actual), e);
    }
}
Also used : Delta(org.assertj.core.util.diff.Delta) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 8 with Delta

use of org.assertj.core.util.diff.Delta in project assertj-core by joel-costigliola.

the class Paths method assertHasSameContentAs.

public void assertHasSameContentAs(AssertionInfo info, Path actual, Charset actualCharset, Path expected, Charset expectedCharset) {
    checkNotNull(expected, "The given Path to compare actual content to should not be null");
    checkArgument(nioFilesWrapper.isReadable(expected), "The given Path <%s> to compare actual content to should be readable", expected);
    assertIsReadable(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 (IOException e) {
        throw new UncheckedIOException(format("Unable to compare contents of paths:<%s> and:<%s>", actual, expected), e);
    }
}
Also used : Delta(org.assertj.core.util.diff.Delta) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 9 with Delta

use of org.assertj.core.util.diff.Delta in project assertj-core by joel-costigliola.

the class Paths_assertHasContent_Test method should_fail_if_path_does_not_have_expected_text_content.

@Test
public void should_fail_if_path_does_not_have_expected_text_content() throws IOException {
    @SuppressWarnings("unchecked") List<Delta<String>> diffs = newArrayList((Delta<String>) mock(Delta.class));
    when(diff.diff(path, expected, charset)).thenReturn(diffs);
    when(nioFilesWrapper.exists(path)).thenReturn(true);
    when(nioFilesWrapper.isReadable(path)).thenReturn(true);
    AssertionInfo info = someInfo();
    try {
        paths.assertHasContent(info, path, expected, charset);
    } catch (AssertionError e) {
        verify(failures).failure(info, shouldHaveContent(path, charset, diffs));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) Delta(org.assertj.core.util.diff.Delta) PathsBaseTest(org.assertj.core.internal.PathsBaseTest) Test(org.junit.Test)

Example 10 with Delta

use of org.assertj.core.util.diff.Delta in project assertj-core by joel-costigliola.

the class Paths_assertHasSameContentAs_Test method should_fail_if_actual_and_given_path_does_not_have_the_same_content.

@Test
public void should_fail_if_actual_and_given_path_does_not_have_the_same_content() throws IOException {
    @SuppressWarnings("unchecked") List<Delta<String>> diffs = newArrayList((Delta<String>) mock(Delta.class));
    when(diff.diff(actual, defaultCharset(), other, defaultCharset())).thenReturn(diffs);
    when(nioFilesWrapper.exists(actual)).thenReturn(true);
    when(nioFilesWrapper.isReadable(actual)).thenReturn(true);
    when(nioFilesWrapper.isReadable(other)).thenReturn(true);
    AssertionInfo info = someInfo();
    try {
        paths.assertHasSameContentAs(info, actual, defaultCharset(), other, defaultCharset());
    } catch (AssertionError e) {
        verify(failures).failure(info, shouldHaveSameContent(actual, other, diffs));
        return;
    }
    failBecauseExpectedAssertionErrorWasNotThrown();
}
Also used : AssertionInfo(org.assertj.core.api.AssertionInfo) Delta(org.assertj.core.util.diff.Delta) Test(org.junit.Test)

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