package org.zwobble.mammoth.tests.docx; import com.google.common.collect.ImmutableList; import org.hamcrest.Matcher; import org.junit.Test; import org.zwobble.mammoth.documents.DocumentElement; import org.zwobble.mammoth.documents.RunElement; import org.zwobble.mammoth.documents.TextElement; import org.zwobble.mammoth.xml.XmlElement; import org.zwobble.mammoth.xml.XmlNode; import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import static org.zwobble.mammoth.docx.BodyXml.readBodyXmlElement; import static org.zwobble.mammoth.xml.XmlNodes.element; import static org.zwobble.mammoth.xml.XmlNodes.text; public class BodyXmlTests { @Test public void textFromTextElementIsRead() { XmlElement element = textXml("Hello!"); assertThat(readBodyXmlElement(element), isTextElement("Hello!")); } @Test public void canReadTextWithinRun() { XmlElement element = runXml(ImmutableList.of(textXml("Hello!"))); assertThat( readBodyXmlElement(element), isRunElement(isTextElement("Hello!"))); } private XmlElement runXml(List children) { return element("w:r", children); } private XmlElement textXml(String value) { return element("w:t", ImmutableList.of(text(value))); } private Matcher isRunElement(Matcher child) { return allOf( instanceOf(RunElement.class), hasProperty("children", contains(child))); } private Matcher isTextElement(String value) { return allOf( instanceOf(TextElement.class), hasProperty("value", equalTo(value))); } }