diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-23 21:40:41 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-23 21:40:41 +0000 |
| commit | 0b5985ee2ea46d0cee65400224ba3e9326f1ec12 (patch) | |
| tree | 975a3e23f221b79d92cda95e01c4822ad0b9aea2 | |
| parent | aef35f53a0987a01f40557b19cdafdd15aa9bdcd (diff) | |
Add test for missing main document part
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java index d7f1a11..cfcc4e9 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentReaderTests.java @@ -1,22 +1,26 @@ package org.zwobble.mammoth.tests.docx; import org.junit.jupiter.api.Test; +import org.zwobble.mammoth.internal.archives.Archive; import org.zwobble.mammoth.internal.archives.InMemoryArchive; import org.zwobble.mammoth.internal.documents.Document; import org.zwobble.mammoth.internal.docx.DocumentReader; import org.zwobble.mammoth.internal.results.InternalResult; +import org.zwobble.mammoth.internal.util.PassThroughException; import org.zwobble.mammoth.internal.xml.NamespacePrefixes; import org.zwobble.mammoth.internal.xml.XmlWriter; import java.util.Optional; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; import static org.zwobble.mammoth.internal.util.Lists.list; import static org.zwobble.mammoth.internal.util.Maps.map; import static org.zwobble.mammoth.internal.xml.XmlNodes.element; import static org.zwobble.mammoth.internal.xml.XmlNodes.text; import static org.zwobble.mammoth.tests.ResultMatchers.isInternalSuccess; import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*; +import static org.zwobble.mammoth.tests.util.MammothAsserts.assertThrows; public class DocumentReaderTests { private final NamespacePrefixes mainDocumentNamespaces = NamespacePrefixes.builder() @@ -57,4 +61,25 @@ public class DocumentReaderTests { withChildren(paragraphWithText("Hello.")) ))); } + + @Test + public void errorIsThrownWhenMainDocumentPartDoesNotExist() { + Archive archive = InMemoryArchive.fromStrings(map( + "_rels/.rels", XmlWriter.toString( + element("Relationships", list( + element("Relationship", map( + "Id", "rId1", + "Target", "/word/document2.xml", + "Type", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" + )) + )), + relationshipsNamespaces + ) + )); + PassThroughException exception = assertThrows( + PassThroughException.class, + () -> DocumentReader.readDocument(Optional.empty(), archive) + ); + assertThat(exception.getMessage(), equalTo("java.io.IOException: Could not find main document part. Are you sure this is a valid .docx file?")); + } } |
