diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:26:45 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-01-02 22:26:45 +0000 |
| commit | 871df6bd1a1f7c45e750a49589c7a195c3506205 (patch) | |
| tree | 11b552f4c2e12ec1242852c047446d1f27df20f3 /src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java | |
| parent | d5005305b90afe47e639fc0fa1430242556f0385 (diff) | |
Add reading of style IDs
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java index e2ee5a9..b0152a5 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java @@ -1,6 +1,7 @@ package org.zwobble.mammoth.tests.docx; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.hamcrest.Matcher; import org.junit.Test; import org.zwobble.mammoth.documents.DocumentElement; @@ -13,9 +14,12 @@ import org.zwobble.mammoth.xml.XmlNode; import org.zwobble.mammoth.xml.XmlNodes; import java.util.List; +import java.util.Optional; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasProperty; import static org.zwobble.mammoth.docx.BodyXml.readBodyXmlElement; import static org.zwobble.mammoth.xml.XmlNodes.element; @@ -42,6 +46,28 @@ public class BodyXmlTests { isParagraph(paragraph(run(text("Hello!"))))); } + @Test + public void paragraphHasNoStyleIfItHasNoProperties() { + XmlElement element = paragraphXml(); + assertThat( + readBodyXmlElement(element), + hasStyleId(Optional.empty())); + } + + @Test + public void paragraphHasStyleIdReadFromParagraphPropertiesIfPresent() { + XmlElement element = paragraphXml(ImmutableList.of( + element("w:pPr", ImmutableList.of( + element("w:pStyle", ImmutableMap.of("w:val", "Heading1")))))); + assertThat( + readBodyXmlElement(element), + hasStyleId(Optional.of("Heading1"))); + } + + private XmlElement paragraphXml() { + return paragraphXml(ImmutableList.of()); + } + private XmlElement paragraphXml(List<XmlNode> children) { return element("w:p", children); } @@ -66,8 +92,12 @@ public class BodyXmlTests { return new DeepReflectionMatcher<>(new TextElement(value)); } + private Matcher<? super DocumentElement> hasStyleId(Optional<String> expected) { + return hasProperty("styleId", equalTo(expected)); + } + private ParagraphElement paragraph(DocumentElement... children) { - return new ParagraphElement(asList(children)); + return new ParagraphElement(Optional.empty(), asList(children)); } private RunElement run(DocumentElement... children) { |
