aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java
blob: 16d14ad3f9f7eb62a7c83c28c9dd3c647c52c482 (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
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.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.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH;
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", ImmutableList.of(
            element("w:footnote", ImmutableMap.of("w:id", "1"), ImmutableList.of(
                element("w:p")))));

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

        assertThat(
            notes,
            deepEquals(ImmutableList.of(new Note("1", ImmutableList.of(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", ImmutableList.of(
            element("w:footnote", ImmutableMap.of("w:id", "1", "w:type", noteType), ImmutableList.of(
                element("w:p")))));

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

        assertThat(notes, deepEquals(ImmutableList.of()));
    }
}