From c1604e510cc831a00f6105df35c68a856f061b65 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 21 Feb 2016 09:44:16 +0000 Subject: Allow input streams to be read --- .../org/zwobble/mammoth/tests/MammothTests.java | 47 +++++++++++++++------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'src/test/java/org/zwobble/mammoth/tests/MammothTests.java') diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index 603d39a..52efde2 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -16,42 +16,42 @@ import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; public class MammothTests { @Test - public void docxContainingOneParagraphIsConvertedToSingleParagraphElement() { + public void docxContainingOneParagraphIsConvertedToSingleParagraphElement() throws IOException { assertThat( convertToHtml("single-paragraph.docx"), deepEquals(success("

Walking on imported air

"))); } @Test - public void canReadFilesWithUtf8Bom() { + public void canReadFilesWithUtf8Bom() throws IOException { assertThat( convertToHtml("utf8-bom.docx"), deepEquals(success("

This XML has a byte order mark.

"))); } @Test - public void emptyParagraphsAreIgnoredByDefault() { + public void emptyParagraphsAreIgnoredByDefault() throws IOException { assertThat( convertToHtml("empty.docx"), deepEquals(success(""))); } @Test - public void emptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() { + public void emptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() throws IOException { assertThat( convertToHtml("empty.docx", Mammoth.Options.DEFAULT.preserveEmptyParagraphs()), deepEquals(success("

"))); } @Test - public void simpleListIsConvertedToListElements() { + public void simpleListIsConvertedToListElements() throws IOException { assertThat( convertToHtml("simple-list.docx"), deepEquals(success(""))); } @Test - public void wordTablesAreConvertedToHtmlTables() { + public void wordTablesAreConvertedToHtmlTables() throws IOException { assertThat( convertToHtml("tables.docx"), deepEquals(success( @@ -64,7 +64,7 @@ public class MammothTests { } @Test - public void inlineImagesAreIncludedInOutput() { + public void inlineImagesAreIncludedInOutput() throws IOException { assertThat( convertToHtml("tiny-picture.docx"), deepEquals(success("

"))); @@ -85,6 +85,23 @@ public class MammothTests { } } + @Test + public void warnIfDocumentHasImagesStoredOutsideOfDocumentWhenPathOfDocumentIsUnknown() throws IOException { + Path tempDirectory = Files.createTempDirectory("mammoth-"); + try { + Path documentPath = tempDirectory.resolve("external-picture.docx"); + Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); + assertThat( + Mammoth.convertToHtml(documentPath.toUri().toURL().openStream()), + allOf( + hasProperty("value", equalTo("")), + hasProperty("warnings", contains( + hasProperty("message", startsWith("could not open external image 'tiny-picture.png': path of document is unknown, but is required for relative URI")))))); + } finally { + tempDirectory.toFile().delete(); + } + } + @Test public void warnIfImagesStoredOutsideOfDocumentAreNotFound() throws IOException { Path tempDirectory = Files.createTempDirectory("mammoth-"); @@ -103,14 +120,14 @@ public class MammothTests { } @Test - public void contentTypesAreRead() { + public void contentTypesAreRead() throws IOException { assertThat( convertToHtml("tiny-picture-custom-content-type.docx"), deepEquals(success("

"))); } @Test - public void footnotesAreAppendedToText() { + public void footnotesAreAppendedToText() throws IOException { assertThat( convertToHtml("footnotes.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")), deepEquals(success( @@ -122,7 +139,7 @@ public class MammothTests { } @Test - public void endNotesAreAppendedToText() { + public void endNotesAreAppendedToText() throws IOException { assertThat( convertToHtml("endnotes.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")), deepEquals(success( @@ -134,7 +151,7 @@ public class MammothTests { } @Test - public void relationshipsAreReadForEachFileContainingBodyXml() { + public void relationshipsAreReadForEachFileContainingBodyXml() throws IOException { assertThat( convertToHtml("footnote-hyperlink.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")), deepEquals(success( @@ -143,25 +160,25 @@ public class MammothTests { } @Test - public void textBoxesAreRead() { + public void textBoxesAreRead() throws IOException { assertThat( convertToHtml("text-box.docx"), deepEquals(success("

Datum plane

"))); } @Test - public void canExtractRawText() { + public void canExtractRawText() throws IOException { assertThat( Mammoth.extractRawText(TestData.file("simple-list.docx")), deepEquals(success("Apple\n\nBanana\n\n"))); } - private Result convertToHtml(String name) { + private Result convertToHtml(String name) throws IOException { File file = TestData.file(name); return Mammoth.convertToHtml(file); } - private Result convertToHtml(String name, Mammoth.Options options) { + private Result convertToHtml(String name, Mammoth.Options options) throws IOException { File file = TestData.file(name); return Mammoth.convertToHtml(file, options); } -- cgit v1.2.3