aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java
blob: d18cbe3a0e787dac2ba9444ad8d355abac47c4d4 (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
55
56
57
58
59
package org.zwobble.mammoth.tests.docx;

import org.junit.Test;
import org.zwobble.mammoth.Result;
import org.zwobble.mammoth.documents.Note;
import org.zwobble.mammoth.docx.BodyXmlReader;
import org.zwobble.mammoth.docx.NotesXmlReader;
import org.zwobble.mammoth.xml.XmlElement;

import java.util.List;

import static com.natpryce.makeiteasy.MakeItEasy.a;
import static com.natpryce.makeiteasy.MakeItEasy.make;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.zwobble.mammoth.Result.success;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH;
import static org.zwobble.mammoth.util.MammothLists.list;
import static org.zwobble.mammoth.util.MammothMaps.map;
import static org.zwobble.mammoth.xml.XmlNodes.element;

public class NotesXmlReaderTests {
    private static final BodyXmlReader bodyReader = make(a(BodyXmlReaderMakers.bodyReader));

    @Test
    public void idAndBodyOfFootnoteAreRead() {
        XmlElement element = element("w:footnotes", list(
            element("w:footnote", map("w:id", "1"), list(
                element("w:p")))));

        NotesXmlReader reader = new NotesXmlReader(bodyReader, "footnote");
        Result<List<Note>> notes = reader.readElement(element);

        assertThat(
            notes,
            deepEquals(success(list(new Note("1", list(make(a(PARAGRAPH))))))));
    }

    @Test
    public void continuationSeparatorIsIgnored() {
        assertFootnoteTypeIsIgnored("continuationSeparator");
    }

    @Test
    public void separatorIsIgnored() {
        assertFootnoteTypeIsIgnored("separator");
    }

    private void assertFootnoteTypeIsIgnored(String noteType) {
        XmlElement element = element("w:footnotes", list(
            element("w:footnote", map("w:id", "1", "w:type", noteType), list(
                element("w:p")))));

        NotesXmlReader reader = new NotesXmlReader(bodyReader, "footnote");
        Result<List<Note>> notes = reader.readElement(element);

        assertThat(notes, deepEquals(success(list())));
    }
}