diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-01-03 11:53:34 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-01-03 11:53:34 +0000 |
| commit | 8733a942ec5e53a1f4d5ac78ffaaf8badfdee2cf (patch) | |
| tree | 4bad0320d2f462d83ed0e50a9431ad149dee2433 /src/test/java/org/zwobble/mammoth | |
| parent | df0e65ca725de5fb471abdd7ff8621904e41a209 (diff) | |
Add reading of notes XML
Diffstat (limited to 'src/test/java/org/zwobble/mammoth')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java new file mode 100644 index 0000000..e1f65ab --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java @@ -0,0 +1,54 @@ +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.documents.Paragraph; +import org.zwobble.mammoth.docx.BodyXmlReader; +import org.zwobble.mammoth.docx.NotesXmlReader; +import org.zwobble.mammoth.xml.XmlElement; + +import java.util.List; +import java.util.Optional; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; +import static org.zwobble.mammoth.xml.XmlNodes.element; + +public class NotesXmlReaderTests { + @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(new BodyXmlReader(null), "footnote"); + List<Note> notes = reader.readElement(element); + + assertThat( + notes, + deepEquals(ImmutableList.of(new Note("1", ImmutableList.of(new Paragraph(Optional.empty(), ImmutableList.of())))))); + } + + @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(new BodyXmlReader(null), "footnote"); + List<Note> notes = reader.readElement(element); + + assertThat(notes, deepEquals(ImmutableList.of())); + } +} |
