diff options
Diffstat (limited to 'src/test')
3 files changed, 31 insertions, 14 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java index 3ae5d16..17bcdf1 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java @@ -37,7 +37,7 @@ public class DocumentConverterTests { assertThat( documentConverter().convertToHtml(new Document(list( make(a(PARAGRAPH, with(CHILDREN, list(runWithText("Hello"))))), - make(a(PARAGRAPH, with(CHILDREN, list(runWithText("there")))))))), + make(a(PARAGRAPH, with(CHILDREN, list(runWithText("there")))))), Notes.EMPTY)), deepEquals(list( Html.element("p", list(Html.text("Hello"))), diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java index 5370db3..3eaa4ee 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java @@ -2,23 +2,25 @@ package org.zwobble.mammoth.tests.docx; import org.junit.Test; import org.zwobble.mammoth.documents.Document; -import org.zwobble.mammoth.documents.Text; -import org.zwobble.mammoth.docx.BodyXmlReader; +import org.zwobble.mammoth.documents.Note; +import org.zwobble.mammoth.documents.NoteType; +import org.zwobble.mammoth.documents.Notes; import org.zwobble.mammoth.docx.DocumentXmlReader; import org.zwobble.mammoth.results.Result; import org.zwobble.mammoth.xml.XmlElement; import org.zwobble.mammoth.xml.XmlNodes; -import static com.natpryce.makeiteasy.MakeItEasy.*; +import static com.natpryce.makeiteasy.MakeItEasy.a; +import static com.natpryce.makeiteasy.MakeItEasy.make; import static org.hamcrest.MatcherAssert.assertThat; import static org.zwobble.mammoth.results.Result.success; import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; -import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*; +import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.paragraphWithText; +import static org.zwobble.mammoth.tests.docx.BodyXmlReaderMakers.bodyReader; import static org.zwobble.mammoth.util.MammothLists.list; import static org.zwobble.mammoth.xml.XmlNodes.element; public class DocumentXmlTests { - private static final BodyXmlReader bodyReader = make(a(BodyXmlReaderMakers.bodyReader)); @Test public void canReadTextWithinDocument() { @@ -29,13 +31,27 @@ public class DocumentXmlTests { element("w:t", list( XmlNodes.text("Hello!"))))))))))); - Result<Document> document = new DocumentXmlReader(bodyReader).readElement(documentElement); + DocumentXmlReader reader = new DocumentXmlReader(make(a(bodyReader)), Notes.EMPTY); + Result<Document> document = reader.readElement(documentElement); assertThat( document, - deepEquals(success(new Document(list( - make(a(PARAGRAPH, with(CHILDREN, list( - make(a(RUN, with(CHILDREN, list( - new Text("Hello!")))))))))))))); + deepEquals(success(new Document( + list(paragraphWithText("Hello!")), + Notes.EMPTY)))); + } + + @Test + public void notesOfDocumentAreIncludedInDocument() { + Note note = new Note(NoteType.FOOTNOTE, "4", list(paragraphWithText("Hello"))); + Notes notes = new Notes(list(note)); + DocumentXmlReader reader = new DocumentXmlReader(make(a(bodyReader)), notes); + + XmlElement documentElement = element("w:document", list(element("w:body"))); + Result<Document> document = reader.readElement(documentElement); + + assertThat( + document.getValue().getNotes().findNote(NoteType.FOOTNOTE, "4").get(), + deepEquals(note)); } } diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java index ef8489a..a5d5be7 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java @@ -1,6 +1,7 @@ package org.zwobble.mammoth.tests.docx; import org.junit.Test; +import org.zwobble.mammoth.documents.NoteType; import org.zwobble.mammoth.results.Result; import org.zwobble.mammoth.documents.Note; import org.zwobble.mammoth.docx.BodyXmlReader; @@ -28,12 +29,12 @@ public class NotesXmlReaderTests { element("w:footnote", map("w:id", "1"), list( element("w:p"))))); - NotesXmlReader reader = new NotesXmlReader(bodyReader, "footnote"); + NotesXmlReader reader = NotesXmlReader.footnote(bodyReader); Result<List<Note>> notes = reader.readElement(element); assertThat( notes, - deepEquals(success(list(new Note("1", list(make(a(PARAGRAPH)))))))); + deepEquals(success(list(new Note(NoteType.FOOTNOTE, "1", list(make(a(PARAGRAPH)))))))); } @Test @@ -51,7 +52,7 @@ public class NotesXmlReaderTests { element("w:footnote", map("w:id", "1", "w:type", noteType), list( element("w:p"))))); - NotesXmlReader reader = new NotesXmlReader(bodyReader, "footnote"); + NotesXmlReader reader = NotesXmlReader.footnote(bodyReader); Result<List<Note>> notes = reader.readElement(element); assertThat(notes, deepEquals(success(list()))); |
