diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-12-31 21:05:46 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-12-31 21:05:46 +0000 |
| commit | 26af8fca2838549a185345458bbdb24db8a62d9b (patch) | |
| tree | b14490ce2b05de4f39cc1b349f951948dd37eb3c /src/test/java | |
| parent | 10fb9097c90d531445a290e29dcb29f9bcc8885a (diff) | |
Add reading of styles XML
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/docx/StylesXmlTests.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/StylesXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/StylesXmlTests.java new file mode 100644 index 0000000..eb28af9 --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/docx/StylesXmlTests.java @@ -0,0 +1,76 @@ +package org.zwobble.mammoth.tests.docx; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import org.junit.Test; +import org.zwobble.mammoth.docx.Styles; +import org.zwobble.mammoth.xml.XmlElement; + +import java.util.Optional; + +import static org.junit.Assert.assertEquals; +import static org.zwobble.mammoth.docx.StylesXml.readStylesXmlElement; +import static org.zwobble.mammoth.xml.XmlNodes.element; + +public class StylesXmlTests { + @Test + public void paragraphStyleIsNoneIfNoStyleWithThatIdExists() { + XmlElement element = element("w:styles"); + + Styles styles = readStylesXmlElement(element); + + assertEquals(Optional.empty(), styles.findParagraphStyleById("Heading1")); + } + + @Test + public void paragraphStyleCanBeFoundById() { + XmlElement element = element("w:styles", ImmutableList.of( + element("w:style", ImmutableMap.of("w:type", "paragraph", "w:styleId", "Heading1"), ImmutableList.of( + nameElement("Heading 1"))))); + + Styles styles = readStylesXmlElement(element); + + assertEquals(Optional.of("Heading 1"), styles.findParagraphStyleById("Heading1").get().getName()); + } + + @Test + public void characterStyleCanBeFoundById() { + XmlElement element = element("w:styles", ImmutableList.of( + element("w:style", ImmutableMap.of("w:type", "character", "w:styleId", "Heading1Char"), ImmutableList.of( + nameElement("Heading 1 Char"))))); + + Styles styles = readStylesXmlElement(element); + + assertEquals(Optional.of("Heading 1 Char"), styles.findCharacterStyleById("Heading1Char").get().getName()); + } + + @Test + public void paragraphAndCharacterStylesAreDistinct() { + XmlElement element = element("w:styles", ImmutableList.of( + element("w:style", ImmutableMap.of("w:type", "paragraph", "w:styleId", "Heading1"), ImmutableList.of( + nameElement("Heading 1"))), + element("w:style", ImmutableMap.of("w:type", "character", "w:styleId", "Heading1Char"), ImmutableList.of( + nameElement("Heading 1 Char"))))); + + Styles styles = readStylesXmlElement(element); + + assertEquals(Optional.empty(), styles.findCharacterStyleById("Heading1")); + assertEquals(Optional.empty(), styles.findParagraphStyleById("Heading1Char")); + } + + @Test + public void styleNameIsNoneIfNameElementDoesNotExist() { + XmlElement element = element("w:styles", ImmutableList.of( + element("w:style", ImmutableMap.of("w:type", "paragraph", "w:styleId", "Heading1")), + element("w:style", ImmutableMap.of("w:type", "character", "w:styleId", "Heading1Char")))); + + Styles styles = readStylesXmlElement(element); + + assertEquals(Optional.empty(), styles.findParagraphStyleById("Heading1").get().getName()); + assertEquals(Optional.empty(), styles.findCharacterStyleById("Heading1Char").get().getName()); + } + + private XmlElement nameElement(String name) { + return element("w:name", ImmutableMap.of("w:val", name)); + } +} |
