blob: 11cbaa93babb19e813cf677e9ebee87aeb30ff28 (
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
|
package org.zwobble.mammoth.tests.docx;
import com.google.common.collect.ImmutableList;
import com.natpryce.makeiteasy.Instantiator;
import com.natpryce.makeiteasy.Property;
import com.natpryce.makeiteasy.PropertyLookup;
import org.junit.Test;
import org.zwobble.mammoth.documents.*;
import org.zwobble.mammoth.docx.BodyXmlReader;
import org.zwobble.mammoth.docx.DocumentXmlReader;
import org.zwobble.mammoth.xml.XmlElement;
import org.zwobble.mammoth.xml.XmlNodes;
import java.util.List;
import java.util.Optional;
import static com.natpryce.makeiteasy.MakeItEasy.*;
import static com.natpryce.makeiteasy.Property.newProperty;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.xml.XmlNodes.element;
public class DocumentXmlTests {
private static final Property<HasChildren, List<DocumentElement>> CHILDREN = newProperty();
private static final Instantiator<ParagraphElement> paragraph = new Instantiator<ParagraphElement>() {
@Override
public ParagraphElement instantiate(PropertyLookup<ParagraphElement> propertyLookup) {
return new ParagraphElement(
Optional.empty(),
propertyLookup.valueOf(CHILDREN, ImmutableList.of()));
}
};
@Test
public void canReadTextWithinDocument() {
XmlElement documentElement = element("w:document", ImmutableList.of(
element("w:body", ImmutableList.of(
element("w:p", ImmutableList.of(
element("w:r", ImmutableList.of(
element("w:t", ImmutableList.of(
XmlNodes.text("Hello!")))))))))));
Document document = new DocumentXmlReader(new BodyXmlReader(null)).readElement(documentElement);
assertThat(
document,
deepEquals(new Document(ImmutableList.of(
make(a(paragraph, with(CHILDREN, ImmutableList.of(
new RunElement(ImmutableList.of(
new TextElement("Hello!")))))))))));
}
}
|