From d5da134fe3107acc53987ed6ca89cefd72e0397e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 3 Jan 2016 10:58:44 +0000 Subject: Add reading of document.xml --- .../mammoth/tests/docx/DocumentXmlTests.java | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java (limited to 'src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java') diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java new file mode 100644 index 0000000..114c1b0 --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java @@ -0,0 +1,53 @@ +package org.zwobble.mammoth.tests.docx; + +import com.google.common.collect.ImmutableList; +import com.natpryce.makeiteasy.Instantiator; +import com.natpryce.makeiteasy.Property; +import com.natpryce.makeiteasy.PropertyLookup; +import org.junit.Test; +import org.zwobble.mammoth.documents.*; +import org.zwobble.mammoth.docx.BodyXml; +import org.zwobble.mammoth.docx.DocumentXml; +import org.zwobble.mammoth.xml.XmlElement; +import org.zwobble.mammoth.xml.XmlNodes; + +import java.util.List; +import java.util.Optional; + +import static com.natpryce.makeiteasy.MakeItEasy.*; +import static com.natpryce.makeiteasy.Property.newProperty; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; +import static org.zwobble.mammoth.xml.XmlNodes.element; + +public class DocumentXmlTests { + private static final Property> CHILDREN = newProperty(); + + private static final Instantiator paragraph = new Instantiator() { + @Override + public ParagraphElement instantiate(PropertyLookup propertyLookup) { + return new ParagraphElement( + Optional.empty(), + propertyLookup.valueOf(CHILDREN, ImmutableList.of())); + } + }; + + @Test + public void canReadTextWithinDocument() { + XmlElement documentElement = element("w:document", ImmutableList.of( + element("w:body", ImmutableList.of( + element("w:p", ImmutableList.of( + element("w:r", ImmutableList.of( + element("w:t", ImmutableList.of( + XmlNodes.text("Hello!"))))))))))); + + Document document = new DocumentXml(new BodyXml(null)).readDocumentXmlElement(documentElement); + + assertThat( + document, + deepEquals(new Document(ImmutableList.of( + make(a(paragraph, with(CHILDREN, ImmutableList.of( + new RunElement(ImmutableList.of( + new TextElement("Hello!"))))))))))); + } +} -- cgit v1.2.3