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();
}
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);
}
}
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);
}
}
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();
}
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();
}
Aggregations