diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-03-26 09:27:45 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-03-26 09:27:45 +0000 |
| commit | abbcc3915fa783c648436ef52e15da923a246dd1 (patch) | |
| tree | 2db501fd1a82dc608217623cc53b8a6b13f71bb5 /src/test/java/org/zwobble/mammoth/tests/MammothTests.java | |
| parent | 55ec6fed7278825bee4b6db24965b69b9c496ed5 (diff) | |
Lazily combine warnings in results
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/MammothTests.java')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/MammothTests.java | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index 7dc373c..8ac7af3 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -12,65 +12,64 @@ import java.util.function.Function; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; -import static org.zwobble.mammoth.internal.results.InternalResult.success; import static org.zwobble.mammoth.internal.util.MammothLists.list; -import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; import static org.zwobble.mammoth.tests.ResultMatchers.isResult; +import static org.zwobble.mammoth.tests.ResultMatchers.isSuccess; public class MammothTests { @Test public void docxContainingOneParagraphIsConvertedToSingleParagraphElement() throws IOException { assertThat( convertToHtml("single-paragraph.docx"), - deepEquals(success("<p>Walking on imported air</p>"))); + isSuccess("<p>Walking on imported air</p>")); } @Test public void canReadFilesWithUtf8Bom() throws IOException { assertThat( convertToHtml("utf8-bom.docx"), - deepEquals(success("<p>This XML has a byte order mark.</p>"))); + isSuccess("<p>This XML has a byte order mark.</p>")); } @Test public void emptyParagraphsAreIgnoredByDefault() throws IOException { assertThat( convertToHtml("empty.docx"), - deepEquals(success(""))); + isSuccess("")); } @Test public void emptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() throws IOException { assertThat( convertToHtml("empty.docx", mammoth -> mammoth.preserveEmptyParagraphs()), - deepEquals(success("<p></p>"))); + isSuccess("<p></p>")); } @Test public void simpleListIsConvertedToListElements() throws IOException { assertThat( convertToHtml("simple-list.docx"), - deepEquals(success("<ul><li>Apple</li><li>Banana</li></ul>"))); + isSuccess("<ul><li>Apple</li><li>Banana</li></ul>")); } @Test public void wordTablesAreConvertedToHtmlTables() throws IOException { assertThat( convertToHtml("tables.docx"), - deepEquals(success( + isSuccess( "<p>Above</p>" + "<table>" + "<tr><td><p>Top left</p></td><td><p>Top right</p></td></tr>" + "<tr><td><p>Bottom left</p></td><td><p>Bottom right</p></td></tr>" + "</table>" + - "<p>Below</p>"))); + "<p>Below</p>")); } @Test public void inlineImagesAreIncludedInOutput() throws IOException { assertThat( convertToHtml("tiny-picture.docx"), - deepEquals(success("<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>"))); + isSuccess("<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>")); } @Test @@ -82,7 +81,7 @@ public class MammothTests { Files.copy(TestData.file("tiny-picture.png").toPath(), tempDirectory.resolve("tiny-picture.png")); assertThat( new DocumentConverter().convertToHtml(documentPath.toFile()), - deepEquals(success("<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>"))); + isSuccess("<p><img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>")); } finally { tempDirectory.toFile().delete(); } @@ -126,68 +125,68 @@ public class MammothTests { public void contentTypesAreRead() throws IOException { assertThat( convertToHtml("tiny-picture-custom-content-type.docx"), - deepEquals(success("<p><img src=\"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>"))); + isSuccess("<p><img src=\"data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=\" /></p>")); } @Test public void footnotesAreAppendedToText() throws IOException { assertThat( convertToHtml("footnotes.docx", mammoth -> mammoth.idPrefix("doc-42-")), - deepEquals(success( + isSuccess( "<p>Ouch" + "<sup><a href=\"#doc-42-footnote-1\" id=\"doc-42-footnote-ref-1\">[1]</a></sup>." + "<sup><a href=\"#doc-42-footnote-2\" id=\"doc-42-footnote-ref-2\">[2]</a></sup></p>" + "<ol><li id=\"doc-42-footnote-1\"><p> A tachyon walks into a bar. <a href=\"#doc-42-footnote-ref-1\">↑</a></p></li>" + - "<li id=\"doc-42-footnote-2\"><p> Fin. <a href=\"#doc-42-footnote-ref-2\">↑</a></p></li></ol>"))); + "<li id=\"doc-42-footnote-2\"><p> Fin. <a href=\"#doc-42-footnote-ref-2\">↑</a></p></li></ol>")); } @Test public void endNotesAreAppendedToText() throws IOException { assertThat( convertToHtml("endnotes.docx", mammoth -> mammoth.idPrefix("doc-42-")), - deepEquals(success( + isSuccess( "<p>Ouch" + "<sup><a href=\"#doc-42-endnote-2\" id=\"doc-42-endnote-ref-2\">[1]</a></sup>." + "<sup><a href=\"#doc-42-endnote-3\" id=\"doc-42-endnote-ref-3\">[2]</a></sup></p>" + "<ol><li id=\"doc-42-endnote-2\"><p> A tachyon walks into a bar. <a href=\"#doc-42-endnote-ref-2\">↑</a></p></li>" + - "<li id=\"doc-42-endnote-3\"><p> Fin. <a href=\"#doc-42-endnote-ref-3\">↑</a></p></li></ol>"))); + "<li id=\"doc-42-endnote-3\"><p> Fin. <a href=\"#doc-42-endnote-ref-3\">↑</a></p></li></ol>")); } @Test public void relationshipsAreReadForEachFileContainingBodyXml() throws IOException { assertThat( convertToHtml("footnote-hyperlink.docx", mammoth -> mammoth.idPrefix("doc-42-")), - deepEquals(success( + isSuccess( "<p><sup><a href=\"#doc-42-footnote-1\" id=\"doc-42-footnote-ref-1\">[1]</a></sup></p>" + - "<ol><li id=\"doc-42-footnote-1\"><p> <a href=\"http://www.example.com\">Example</a> <a href=\"#doc-42-footnote-ref-1\">↑</a></p></li></ol>"))); + "<ol><li id=\"doc-42-footnote-1\"><p> <a href=\"http://www.example.com\">Example</a> <a href=\"#doc-42-footnote-ref-1\">↑</a></p></li></ol>")); } @Test public void textBoxesAreRead() throws IOException { assertThat( convertToHtml("text-box.docx"), - deepEquals(success("<p>Datum plane</p>"))); + isSuccess("<p>Datum plane</p>")); } @Test public void canUseCustomStyleMap() throws IOException { assertThat( convertToHtml("underline.docx", mammoth -> mammoth.addStyleMap("u => em")), - deepEquals(success("<p><strong>The <em>Sunset</em> Tree</strong></p>"))); + isSuccess("<p><strong>The <em>Sunset</em> Tree</strong></p>")); } @Test public void mostRecentlyAddedStyleMapTakesPrecedence() throws IOException { assertThat( convertToHtml("underline.docx", mammoth -> mammoth.addStyleMap("u => em").addStyleMap("u => strong")), - deepEquals(success("<p><strong>The <strong>Sunset</strong> Tree</strong></p>"))); + isSuccess("<p><strong>The <strong>Sunset</strong> Tree</strong></p>")); } @Test public void rulesFromPreviouslyAddedStyleMapsStillTakeEffectIfNotOverriden() throws IOException { assertThat( convertToHtml("underline.docx", mammoth -> mammoth.addStyleMap("u => em").addStyleMap("strike => del")), - deepEquals(success("<p><strong>The <em>Sunset</em> Tree</strong></p>"))); + isSuccess("<p><strong>The <em>Sunset</em> Tree</strong></p>")); } @Test @@ -203,14 +202,14 @@ public class MammothTests { public void canExtractRawTextFromFile() throws IOException { assertThat( new DocumentConverter().extractRawText(TestData.file("simple-list.docx")), - deepEquals(success("Apple\n\nBanana\n\n"))); + isSuccess("Apple\n\nBanana\n\n")); } @Test public void canExtractRawTextFromStream() throws IOException { assertThat( new DocumentConverter().extractRawText(TestData.file("simple-list.docx").toURI().toURL().openStream()), - deepEquals(success("Apple\n\nBanana\n\n"))); + isSuccess("Apple\n\nBanana\n\n")); } private Result<String> convertToHtml(String name) throws IOException { |
