diff options
Diffstat (limited to 'src/test/java')
4 files changed, 33 insertions, 16 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlReaderMakers.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlReaderMakers.java new file mode 100644 index 0000000..a0748b9 --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlReaderMakers.java @@ -0,0 +1,22 @@ +package org.zwobble.mammoth.tests.docx; + +import com.google.common.collect.ImmutableMap; +import com.natpryce.makeiteasy.Instantiator; +import com.natpryce.makeiteasy.Property; +import com.natpryce.makeiteasy.PropertyLookup; +import org.zwobble.mammoth.docx.BodyXmlReader; +import org.zwobble.mammoth.docx.Styles; + +import static com.natpryce.makeiteasy.Property.newProperty; + +public class BodyXmlReaderMakers { + public static final Property<BodyXmlReader, Styles> STYLES = newProperty(); + + public static final Instantiator<BodyXmlReader> bodyReader = new Instantiator<BodyXmlReader>() { + @Override + public BodyXmlReader instantiate(PropertyLookup<BodyXmlReader> propertyLookup) { + return new BodyXmlReader( + propertyLookup.valueOf(STYLES, new Styles(ImmutableMap.of(), ImmutableMap.of()))); + } + }; +} diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java index cae7410..862f014 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java @@ -2,10 +2,7 @@ package org.zwobble.mammoth.tests.docx; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import com.natpryce.makeiteasy.Instantiator; import com.natpryce.makeiteasy.Maker; -import com.natpryce.makeiteasy.Property; -import com.natpryce.makeiteasy.PropertyLookup; import org.hamcrest.Matcher; import org.junit.Test; import org.zwobble.mammoth.documents.*; @@ -21,23 +18,15 @@ import java.util.Optional; import static com.natpryce.makeiteasy.MakeItEasy.a; import static com.natpryce.makeiteasy.MakeItEasy.with; -import static com.natpryce.makeiteasy.Property.newProperty; import static java.util.Arrays.asList; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasProperty; import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; +import static org.zwobble.mammoth.tests.docx.BodyXmlReaderMakers.STYLES; +import static org.zwobble.mammoth.tests.docx.BodyXmlReaderMakers.bodyReader; import static org.zwobble.mammoth.xml.XmlNodes.element; public class BodyXmlTests { - private static final Property<BodyXmlReader, Styles> STYLES = newProperty(); - - private static final Instantiator<BodyXmlReader> bodyReader = new Instantiator<BodyXmlReader>() { - @Override - public BodyXmlReader instantiate(PropertyLookup<BodyXmlReader> propertyLookup) { - return new BodyXmlReader( - propertyLookup.valueOf(STYLES, new Styles(ImmutableMap.of(), ImmutableMap.of()))); - } - }; @Test public void textFromTextElementIsRead() { diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java index 9225d0d..ffe2b2f 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java @@ -21,6 +21,8 @@ import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; import static org.zwobble.mammoth.xml.XmlNodes.element; public class DocumentXmlTests { + private static final BodyXmlReader bodyReader = make(a(BodyXmlReaderMakers.bodyReader)); + private static final Property<HasChildren, List<DocumentElement>> CHILDREN = newProperty(); private static final Instantiator<Paragraph> paragraph = new Instantiator<Paragraph>() { @@ -41,7 +43,7 @@ public class DocumentXmlTests { element("w:t", ImmutableList.of( XmlNodes.text("Hello!"))))))))))); - Document document = new DocumentXmlReader(new BodyXmlReader(null)).readElement(documentElement); + Document document = new DocumentXmlReader(bodyReader).readElement(documentElement); assertThat( document, diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java index e1f65ab..f434927 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java @@ -12,18 +12,22 @@ import org.zwobble.mammoth.xml.XmlElement; import java.util.List; import java.util.Optional; +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.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(new BodyXmlReader(null), "footnote"); + NotesXmlReader reader = new NotesXmlReader(bodyReader, "footnote"); List<Note> notes = reader.readElement(element); assertThat( @@ -46,7 +50,7 @@ public class NotesXmlReaderTests { element("w:footnote", ImmutableMap.of("w:id", "1", "w:type", noteType), ImmutableList.of( element("w:p"))))); - NotesXmlReader reader = new NotesXmlReader(new BodyXmlReader(null), "footnote"); + NotesXmlReader reader = new NotesXmlReader(bodyReader, "footnote"); List<Note> notes = reader.readElement(element); assertThat(notes, deepEquals(ImmutableList.of())); |
