diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/docx/OfficeXmlTests.java | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/OfficeXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/OfficeXmlTests.java index 01f9784..91c89f3 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/OfficeXmlTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/OfficeXmlTests.java @@ -1,5 +1,6 @@ package org.zwobble.mammoth.tests.docx; +import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.zwobble.mammoth.internal.docx.OfficeXml; import org.zwobble.mammoth.internal.xml.XmlElement; @@ -13,22 +14,41 @@ import static org.zwobble.mammoth.internal.util.Lists.list; import static org.zwobble.mammoth.internal.xml.XmlNodes.element; public class OfficeXmlTests { - @Test - public void alternateContentIsReplacedByContentsOfFallback() { - String xmlString = - "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + - "<numbering xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\">" + - "<mc:AlternateContent>" + - "<mc:Choice Requires=\"w14\">" + - "<choice/>" + - "</mc:Choice>" + - "<mc:Fallback>" + - "<fallback/>" + - "</mc:Fallback>" + - "</mc:AlternateContent>" + - "</numbering>"; + @Nested + public class AlternateContentTests { + @Test + public void whenFallbackIsPresentThenFallbackIsRead() { + String xmlString = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + + "<numbering xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\">" + + "<mc:AlternateContent>" + + "<mc:Choice Requires=\"w14\">" + + "<choice/>" + + "</mc:Choice>" + + "<mc:Fallback>" + + "<fallback/>" + + "</mc:Fallback>" + + "</mc:AlternateContent>" + + "</numbering>"; - XmlElement result = OfficeXml.parseXml(new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8))); - assertThat(result.getChildren(), deepEquals(list(element("fallback")))); + XmlElement result = OfficeXml.parseXml(new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8))); + assertThat(result.getChildren(), deepEquals(list(element("fallback")))); + } + + @Test + public void whenFallbackIsNotPresentThenElementIsIgnored() { + String xmlString = + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + + "<numbering xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\">" + + "<mc:AlternateContent>" + + "<mc:Choice Requires=\"w14\">" + + "<choice/>" + + "</mc:Choice>" + + "</mc:AlternateContent>" + + "</numbering>"; + + XmlElement result = OfficeXml.parseXml(new ByteArrayInputStream(xmlString.getBytes(StandardCharsets.UTF_8))); + assertThat(result.getChildren(), deepEquals(list())); + } } } |
