summaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/docx/OfficeXmlTests.java
blob: 91c89f3382c6dcce1d0806ced253c565e290ccc3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.internal.util.Lists.list;
import static org.zwobble.mammoth.internal.xml.XmlNodes.element;

public class OfficeXmlTests {
    @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"))));
        }

        @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()));
        }
    }
}