aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-01-03 12:03:09 +0000
committerMichael Williamson <mike@zwobble.org>2016-01-03 12:03:09 +0000
commitc740b5a709f66372631f762b55137db731d03793 (patch)
tree7d9c828de25193939debebd92cd656d1dfd2b644 /src/test
parentea37dde406b1c7fc35f72216882b7732d6ee5445 (diff)
Use make-it-easy to create paragraphs in tests
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java27
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java9
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java26
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java5
4 files changed, 39 insertions, 28 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java b/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java
new file mode 100644
index 0000000..f2d5317
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java
@@ -0,0 +1,27 @@
+package org.zwobble.mammoth.tests.documents;
+
+import com.google.common.collect.ImmutableList;
+import com.natpryce.makeiteasy.Instantiator;
+import com.natpryce.makeiteasy.Property;
+import com.natpryce.makeiteasy.PropertyLookup;
+import org.zwobble.mammoth.documents.DocumentElement;
+import org.zwobble.mammoth.documents.HasChildren;
+import org.zwobble.mammoth.documents.Paragraph;
+
+import java.util.List;
+import java.util.Optional;
+
+import static com.natpryce.makeiteasy.Property.newProperty;
+
+public class DocumentElementMakers {
+ public static final Property<HasChildren, List<DocumentElement>> CHILDREN = newProperty();
+
+ public static final Instantiator<Paragraph> PARAGRAPH = new Instantiator<Paragraph>() {
+ @Override
+ public Paragraph instantiate(PropertyLookup<Paragraph> propertyLookup) {
+ return new Paragraph(
+ Optional.empty(),
+ propertyLookup.valueOf(CHILDREN, ImmutableList.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 862f014..1ead78c 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -17,11 +17,14 @@ import java.util.List;
import java.util.Optional;
import static com.natpryce.makeiteasy.MakeItEasy.a;
+import static com.natpryce.makeiteasy.MakeItEasy.make;
import static com.natpryce.makeiteasy.MakeItEasy.with;
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.documents.DocumentElementMakers.CHILDREN;
+import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH;
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;
@@ -47,7 +50,7 @@ public class BodyXmlTests {
XmlElement element = paragraphXml(ImmutableList.of(runXml(ImmutableList.of(textXml("Hello!")))));
assertThat(
read(a(bodyReader), element),
- isParagraph(paragraph(run(text("Hello!")))));
+ isParagraph(make(a(PARAGRAPH, with(CHILDREN, asList(run(text("Hello!"))))))));
}
@Test
@@ -119,10 +122,6 @@ public class BodyXmlTests {
return hasProperty("style", deepEquals(expected));
}
- private Paragraph paragraph(DocumentElement... children) {
- return new Paragraph(Optional.empty(), asList(children));
- }
-
private Run run(DocumentElement... children) {
return new Run(asList(children));
}
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 ffe2b2f..47e53fc 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/DocumentXmlTests.java
@@ -1,39 +1,25 @@
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.documents.Document;
+import org.zwobble.mammoth.documents.Run;
+import org.zwobble.mammoth.documents.Text;
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.tests.documents.DocumentElementMakers.CHILDREN;
+import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH;
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>() {
- @Override
- public Paragraph instantiate(PropertyLookup<Paragraph> propertyLookup) {
- return new Paragraph(
- Optional.empty(),
- propertyLookup.valueOf(CHILDREN, ImmutableList.of()));
- }
- };
-
@Test
public void canReadTextWithinDocument() {
XmlElement documentElement = element("w:document", ImmutableList.of(
@@ -48,7 +34,7 @@ public class DocumentXmlTests {
assertThat(
document,
deepEquals(new Document(ImmutableList.of(
- make(a(paragraph, with(CHILDREN, ImmutableList.of(
+ make(a(PARAGRAPH, with(CHILDREN, ImmutableList.of(
new Run(ImmutableList.of(
new Text("Hello!")))))))))));
}
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 f434927..16d14ad 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java
@@ -4,18 +4,17 @@ 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 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 {
@@ -32,7 +31,7 @@ public class NotesXmlReaderTests {
assertThat(
notes,
- deepEquals(ImmutableList.of(new Note("1", ImmutableList.of(new Paragraph(Optional.empty(), ImmutableList.of()))))));
+ deepEquals(ImmutableList.of(new Note("1", ImmutableList.of(make(a(PARAGRAPH)))))));
}
@Test