aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-05-28 20:05:51 +0100
committerMichael Williamson <mike@zwobble.org>2025-05-28 20:05:51 +0100
commitf2e7f5c2851040ff8d24a4002483b5664e205c12 (patch)
treedd5bc4fbd422ad3f488b3053e7fe9fa3605b19dd /src
parent5656d17d01a554c6e767aa47ee59e18c02493dc9 (diff)
Test that AlternateContent without Fallback is ignored
Diffstat (limited to 'src')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/OfficeXmlTests.java52
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()));
+ }
}
}