diff options
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java | 53 |
1 files changed, 53 insertions, 0 deletions
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<HasChildren, List<DocumentElement>> CHILDREN = newProperty(); + + private static final Instantiator<ParagraphElement> paragraph = new Instantiator<ParagraphElement>() { + @Override + public ParagraphElement instantiate(PropertyLookup<ParagraphElement> 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!"))))))))))); + } +} |
