aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/Argument.java23
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/ArgumentKey.java13
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/Arguments.java32
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java75
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java133
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java43
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/CommentXmlTests.java6
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java6
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java73
9 files changed, 245 insertions, 159 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/Argument.java b/src/test/java/org/zwobble/mammoth/tests/Argument.java
new file mode 100644
index 0000000..2030a8a
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/Argument.java
@@ -0,0 +1,23 @@
+package org.zwobble.mammoth.tests;
+
+public class Argument<T> {
+ public static <T> Argument<T> arg(ArgumentKey<T> key, T value) {
+ return new Argument<>(key, value);
+ }
+
+ private final ArgumentKey<T> key;
+ private final T value;
+
+ private Argument(ArgumentKey<T> key, T value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public ArgumentKey<T> getKey() {
+ return key;
+ }
+
+ public T getValue() {
+ return value;
+ }
+}
diff --git a/src/test/java/org/zwobble/mammoth/tests/ArgumentKey.java b/src/test/java/org/zwobble/mammoth/tests/ArgumentKey.java
new file mode 100644
index 0000000..0a6d446
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/ArgumentKey.java
@@ -0,0 +1,13 @@
+package org.zwobble.mammoth.tests;
+
+public class ArgumentKey<T> {
+ private final String name;
+
+ public ArgumentKey(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
diff --git a/src/test/java/org/zwobble/mammoth/tests/Arguments.java b/src/test/java/org/zwobble/mammoth/tests/Arguments.java
index afb20bb..badb35a 100644
--- a/src/test/java/org/zwobble/mammoth/tests/Arguments.java
+++ b/src/test/java/org/zwobble/mammoth/tests/Arguments.java
@@ -18,18 +18,38 @@ public class Arguments {
}
public <T> T get(Class<T> clazz, T defaultValue) {
- Iterator<T> arguments = getAll(clazz).iterator();
- if (!arguments.hasNext()) {
- return defaultValue;
- } else {
- return only(arguments);
- }
+ return onlyOrDefault(getAll(clazz), defaultValue);
+ }
+
+ public <T> T get(ArgumentKey<T> key, T defaultValue) {
+ return onlyOrDefault(getAll(key), defaultValue);
}
private <T> Iterable<T> getAll(Class<T> clazz) {
return Iterables.lazyFilter(asList(arguments), clazz);
}
+ private <T> Iterable<T> getAll(ArgumentKey<T> key) {
+ return Iterables.lazyMap(
+ Iterables.lazyFilter(
+ Iterables.lazyFilter(asList(arguments), Argument.class),
+ argument -> argument.getKey().equals(key)
+ ),
+ argument -> (T)argument.getValue()
+ );
+ }
+
+ private <T> T onlyOrDefault(Iterable<T> iterable, T defaultValue) {
+ return onlyOrDefault(iterable.iterator(), defaultValue);
+ }
+
+ private <T> T onlyOrDefault(Iterator<T> iterator, T defaultValue) {
+ if (!iterator.hasNext()) {
+ return defaultValue;
+ } else {
+ return only(iterator);
+ }
+ }
private <T> T only(Iterable<T> iterable) {
return only(iterable.iterator());
diff --git a/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java b/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java
index 6c1ccbe..eb816af 100644
--- a/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java
@@ -17,7 +17,6 @@ import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Optional;
-import static com.natpryce.makeiteasy.MakeItEasy.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.zwobble.mammoth.internal.documents.VerticalAlignment.SUBSCRIPT;
@@ -33,7 +32,7 @@ public class DocumentToHtmlTests {
@Test
public void plainParagraphIsConvertedToPlainParagraph() {
assertThat(
- convertToHtml(make(a(PARAGRAPH, with(CHILDREN, list(runWithText("Hello")))))),
+ convertToHtml(paragraph(withChildren(runWithText("Hello")))),
deepEquals(list(Html.element("p", list(Html.text("Hello"))))));
}
@@ -41,16 +40,20 @@ public class DocumentToHtmlTests {
public void forceWriteIsInsertedIntoParagraphIfEmptyParagraphsShouldBePreserved() {
DocumentToHtmlOptions options = DocumentToHtmlOptions.DEFAULT.preserveEmptyParagraphs();
assertThat(
- DocumentToHtml.convertToHtml(make(a(PARAGRAPH)), options),
+ DocumentToHtml.convertToHtml(paragraph(), options),
isSuccess(list(Html.element("p", list(Html.FORCE_WRITE)))));
}
@Test
public void multipleParagraphsInDocumentAreConvertedToMultipleParagraphs() {
assertThat(
- convertToHtml(new Document(list(
- make(a(PARAGRAPH, with(CHILDREN, list(runWithText("Hello"))))),
- make(a(PARAGRAPH, with(CHILDREN, list(runWithText("there")))))), Notes.EMPTY)),
+ convertToHtml(new Document(
+ list(
+ paragraph(withChildren(runWithText("Hello"))),
+ paragraph(withChildren(runWithText("there")))
+ ),
+ Notes.EMPTY
+ )),
deepEquals(list(
Html.element("p", list(Html.text("Hello"))),
@@ -61,7 +64,7 @@ public class DocumentToHtmlTests {
public void paragraphStyleMappingsCanBeUsedToMapParagraphs() {
assertThat(
convertToHtml(
- make(a(PARAGRAPH, with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty()))))),
+ paragraph(withStyle(new Style("TipsParagraph", Optional.empty()))),
StyleMap.builder()
.mapParagraph(
ParagraphMatcher.styleId("TipsParagraph"),
@@ -75,7 +78,7 @@ public class DocumentToHtmlTests {
public void warningIfParagraphHasUnrecognisedStyle() {
assertThat(
convertToHtmlResult(
- make(a(PARAGRAPH, with(STYLE, Optional.of(new Style("TipsParagraph", Optional.of("Tips Paragraph"))))))),
+ paragraph(withStyle(new Style("TipsParagraph", Optional.of("Tips Paragraph"))))),
deepEquals(new InternalResult<>(
list(Html.element("p")),
@@ -86,7 +89,7 @@ public class DocumentToHtmlTests {
public void runStyleMappingsCanBeUsedToMapRuns() {
assertThat(
convertToHtml(
- make(a(RUN, with(STYLE, Optional.of(new Style("TipsRun", Optional.empty()))))),
+ run(withStyle(new Style("TipsRun", Optional.empty()))),
StyleMap.builder()
.mapRun(
RunMatcher.styleId("TipsRun"),
@@ -100,9 +103,9 @@ public class DocumentToHtmlTests {
public void warningIfRunHasUnrecognisedStyle() {
assertThat(
convertToHtmlResult(
- make(a(RUN,
- with(STYLE, Optional.of(new Style("TipsRun", Optional.of("Tips Run")))),
- with(CHILDREN, list(new Text("Hello")))))),
+ run(
+ withStyle(new Style("TipsRun", Optional.of("Tips Run"))),
+ withChildren(new Text("Hello")))),
deepEquals(new InternalResult<>(
list(Html.text("Hello")),
@@ -112,7 +115,7 @@ public class DocumentToHtmlTests {
@Test
public void boldRunsAreWrappedInStrongTagsByDefault() {
assertThat(
- convertToHtml(make(a(RUN, with(BOLD, true), with(CHILDREN, list(new Text("Hello")))))),
+ convertToHtml(run(withBold(true), withChildren(new Text("Hello")))),
deepEquals(list(Html.collapsibleElement("strong", list(Html.text("Hello"))))));
}
@@ -120,7 +123,7 @@ public class DocumentToHtmlTests {
public void boldRunsCanBeMappedUsingStyleMapping() {
assertThat(
convertToHtml(
- make(a(RUN, with(BOLD, true), with(CHILDREN, list(new Text("Hello"))))),
+ run(withBold(true), withChildren(new Text("Hello"))),
StyleMap.builder().bold(HtmlPath.element("em")).build()),
deepEquals(list(Html.element("em", list(Html.text("Hello"))))));
}
@@ -128,7 +131,7 @@ public class DocumentToHtmlTests {
@Test
public void italicRunsAreWrappedInEmphasisTags() {
assertThat(
- convertToHtml(make(a(RUN, with(ITALIC, true), with(CHILDREN, list(new Text("Hello")))))),
+ convertToHtml(run(withItalic(true), withChildren(new Text("Hello")))),
deepEquals(list(Html.collapsibleElement("em", list(Html.text("Hello"))))));
}
@@ -136,7 +139,7 @@ public class DocumentToHtmlTests {
public void italicRunsCanBeMappedUsingStyleMapping() {
assertThat(
convertToHtml(
- make(a(RUN, with(ITALIC, true), with(CHILDREN, list(new Text("Hello"))))),
+ run(withItalic(true), withChildren(new Text("Hello"))),
StyleMap.builder().italic(HtmlPath.element("strong")).build()),
deepEquals(list(Html.element("strong", list(Html.text("Hello"))))));
}
@@ -144,7 +147,7 @@ public class DocumentToHtmlTests {
@Test
public void underliningIsIgnoredByDefault() {
assertThat(
- convertToHtml(make(a(RUN, with(UNDERLINE, true), with(CHILDREN, list(new Text("Hello")))))),
+ convertToHtml(run(withUnderline(true), withChildren(new Text("Hello")))),
deepEquals(list(Html.text("Hello"))));
}
@@ -152,7 +155,7 @@ public class DocumentToHtmlTests {
public void underliningCanBeMappedUsingStyleMapping() {
assertThat(
convertToHtml(
- make(a(RUN, with(UNDERLINE, true), with(CHILDREN, list(new Text("Hello"))))),
+ run(withUnderline(true), withChildren(new Text("Hello"))),
StyleMap.builder().underline(HtmlPath.element("em")).build()),
deepEquals(list(Html.element("em", list(Html.text("Hello"))))));
@@ -161,7 +164,7 @@ public class DocumentToHtmlTests {
@Test
public void struckthroughRunsAreWrappedInStrikethroughTagsByDefault() {
assertThat(
- convertToHtml(make(a(RUN, with(STRIKETHROUGH, true), with(CHILDREN, list(new Text("Hello")))))),
+ convertToHtml(run(withStrikethrough(true), withChildren(new Text("Hello")))),
deepEquals(list(Html.collapsibleElement("s", list(Html.text("Hello"))))));
}
@@ -169,7 +172,7 @@ public class DocumentToHtmlTests {
public void struckthroughRunsCanBeMappedUsingStyleMapping() {
assertThat(
convertToHtml(
- make(a(RUN, with(STRIKETHROUGH, true), with(CHILDREN, list(new Text("Hello"))))),
+ run(withStrikethrough(true), withChildren(new Text("Hello"))),
StyleMap.builder().strikethrough(HtmlPath.element("del")).build()),
deepEquals(list(Html.element("del", list(Html.text("Hello"))))));
}
@@ -177,14 +180,14 @@ public class DocumentToHtmlTests {
@Test
public void superscriptRunsAreWrappedInSuperscriptTags() {
assertThat(
- convertToHtml(make(a(RUN, with(VERTICAL_ALIGNMENT, SUPERSCRIPT), with(CHILDREN, list(new Text("Hello")))))),
+ convertToHtml(run(withVerticalAlignment(SUPERSCRIPT), withChildren(new Text("Hello")))),
deepEquals(list(Html.collapsibleElement("sup", list(Html.text("Hello"))))));
}
@Test
public void subscriptRunsAreWrappedInSubscriptTags() {
assertThat(
- convertToHtml(make(a(RUN, with(VERTICAL_ALIGNMENT, SUBSCRIPT), with(CHILDREN, list(new Text("Hello")))))),
+ convertToHtml(run(withVerticalAlignment(SUBSCRIPT), withChildren(new Text("Hello")))),
deepEquals(list(Html.collapsibleElement("sub", list(Html.text("Hello"))))));
}
@@ -207,11 +210,11 @@ public class DocumentToHtmlTests {
assertThat(
convertToHtml(new Table(list(
new TableRow(list(
- tableCell(list(paragraphWithText("Top left"))),
- tableCell(list(paragraphWithText("Top right"))))),
+ tableCell(withChildren(paragraphWithText("Top left"))),
+ tableCell(withChildren(paragraphWithText("Top right"))))),
new TableRow(list(
- tableCell(list(paragraphWithText("Bottom left"))),
- tableCell(list(paragraphWithText("Bottom right")))))))),
+ tableCell(withChildren(paragraphWithText("Bottom left"))),
+ tableCell(withChildren(paragraphWithText("Bottom right")))))))),
deepEquals(list(Html.element("table", list(
Html.element("tr", list(
@@ -227,11 +230,11 @@ public class DocumentToHtmlTests {
assertThat(
convertToHtml(new Table(list(
new TableRow(list(
- make(a(TABLE_CELL,
- with(CHILDREN, list(paragraphWithText("Top left"))),
- with(COLSPAN, 2)
- )),
- tableCell(list(paragraphWithText("Top right")))))))),
+ tableCell(
+ withChildren(paragraphWithText("Top left")),
+ withColspan(2)
+ ),
+ tableCell(withChildren(paragraphWithText("Top right")))))))),
deepEquals(list(Html.element("table", list(
Html.element("tr", list(
@@ -247,7 +250,7 @@ public class DocumentToHtmlTests {
assertThat(
convertToHtml(new Table(list(
new TableRow(list(
- make(a(TABLE_CELL, with(ROWSPAN, 2)))
+ tableCell(withRowspan(2))
))
))),
deepEquals(list(Html.element("table", list(
@@ -282,9 +285,9 @@ public class DocumentToHtmlTests {
@Test
public void noteReferencesAreConvertedToLinksToReferenceBodyAfterMainBody() {
Document document = new Document(
- list(make(a(PARAGRAPH, with(CHILDREN, list(
+ list(paragraph(withChildren(
runWithText("Knock knock"),
- make(a(RUN, with(CHILDREN, list(new NoteReference(NoteType.FOOTNOTE, "4")))))))))),
+ run(withChildren(new NoteReference(NoteType.FOOTNOTE, "4")))))),
new Notes(list(new Note(NoteType.FOOTNOTE, "4", list(paragraphWithText("Who's there?"))))));
assertThat(
@@ -305,9 +308,9 @@ public class DocumentToHtmlTests {
@Test
public void noteReferencesAreConvertedWithSequentialNumbers() {
- Run run = make(a(RUN, with(CHILDREN, list(
+ Run run = run(withChildren(
new NoteReference(NoteType.FOOTNOTE, "4"),
- new NoteReference(NoteType.FOOTNOTE, "7")))));
+ new NoteReference(NoteType.FOOTNOTE, "7")));
assertThat(
convertToHtml(run),
diff --git a/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java b/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java
index 0fefd26..433c968 100644
--- a/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java
+++ b/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java
@@ -1,62 +1,105 @@
package org.zwobble.mammoth.tests.documents;
-import com.natpryce.makeiteasy.Instantiator;
-import com.natpryce.makeiteasy.Property;
import org.zwobble.mammoth.internal.documents.*;
+import org.zwobble.mammoth.tests.Argument;
+import org.zwobble.mammoth.tests.ArgumentKey;
+import org.zwobble.mammoth.tests.Arguments;
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 com.natpryce.makeiteasy.Property.newProperty;
+import static java.util.Arrays.asList;
import static org.zwobble.mammoth.internal.util.Lists.list;
+import static org.zwobble.mammoth.tests.Argument.arg;
-public class
-DocumentElementMakers {
- public static final Property<DocumentElement, Optional<Style>> STYLE = newProperty();
- public static final Property<Paragraph, Optional<NumberingLevel>> NUMBERING = newProperty();
- public static final Property<Run, Boolean> BOLD = newProperty();
- public static final Property<Run, Boolean> ITALIC = newProperty();
- public static final Property<Run, Boolean> UNDERLINE = newProperty();
- public static final Property<Run, Boolean> STRIKETHROUGH = newProperty();
- public static final Property<Run, VerticalAlignment> VERTICAL_ALIGNMENT = newProperty();
- public static final Property<HasChildren, List<DocumentElement>> CHILDREN = newProperty();
- public static final Property<TableCell, Integer> COLSPAN = newProperty();
- public static final Property<TableCell, Integer> ROWSPAN = newProperty();
-
- public static final Instantiator<Paragraph> PARAGRAPH =
- propertyLookup -> new Paragraph(
- propertyLookup.valueOf(STYLE, Optional.empty()),
- propertyLookup.valueOf(NUMBERING, Optional.empty()),
- propertyLookup.valueOf(CHILDREN, list()));
-
- public static final Instantiator<Run> RUN =
- propertyLookup -> new Run(
- propertyLookup.valueOf(BOLD, false),
- propertyLookup.valueOf(ITALIC, false),
- propertyLookup.valueOf(UNDERLINE, false),
- propertyLookup.valueOf(STRIKETHROUGH, false),
- propertyLookup.valueOf(VERTICAL_ALIGNMENT, VerticalAlignment.BASELINE),
- propertyLookup.valueOf(STYLE, Optional.empty()),
- propertyLookup.valueOf(CHILDREN, list()));
-
- public static final Instantiator<TableCell> TABLE_CELL =
- propertyLookup -> new TableCell(
- propertyLookup.valueOf(ROWSPAN, 1),
- propertyLookup.valueOf(COLSPAN, 1),
- propertyLookup.valueOf(CHILDREN, list()));
-
- public static TableCell tableCell(List<DocumentElement> children) {
- return make(a(TABLE_CELL, with(CHILDREN, children)));
+public class DocumentElementMakers {
+ private static final ArgumentKey<Optional<Style>> STYLE = new ArgumentKey<>("style");
+ private static final ArgumentKey<Optional<NumberingLevel>> NUMBERING = new ArgumentKey<>("numbering");
+ private static final ArgumentKey<Boolean> BOLD = new ArgumentKey<>("bold");
+ private static final ArgumentKey<Boolean> ITALIC = new ArgumentKey<>("italic");
+ private static final ArgumentKey<Boolean> UNDERLINE = new ArgumentKey<>("underline");
+ private static final ArgumentKey<Boolean> STRIKETHROUGH = new ArgumentKey<>("strikethrough");
+ private static final ArgumentKey<VerticalAlignment> VERTICAL_ALIGNMENT = new ArgumentKey<>("verticalAlignment");
+ private static final ArgumentKey<List<DocumentElement>> CHILDREN = new ArgumentKey<>("children");
+ private static final ArgumentKey<Integer> COLSPAN = new ArgumentKey<>("colspan");
+ private static final ArgumentKey<Integer> ROWSPAN = new ArgumentKey<>("rowspan");
+
+ public static Argument<Optional<Style>> withStyle(Style style) {
+ return arg(STYLE, Optional.of(style));
+ }
+
+ public static Argument<Optional<NumberingLevel>> withNumbering(NumberingLevel numbering) {
+ return arg(NUMBERING, Optional.of(numbering));
+ }
+
+ public static Argument<Boolean> withBold(boolean bold) {
+ return arg(BOLD, bold);
+ }
+
+ public static Argument<Boolean> withItalic(boolean italic) {
+ return arg(ITALIC, italic);
+ }
+
+ public static Argument<Boolean> withUnderline(boolean underline) {
+ return arg(UNDERLINE, underline);
+ }
+
+ public static Argument<Boolean> withStrikethrough(boolean strikethrough) {
+ return arg(STRIKETHROUGH, strikethrough);
+ }
+
+ public static Argument<VerticalAlignment> withVerticalAlignment(VerticalAlignment verticalAlignment) {
+ return arg(VERTICAL_ALIGNMENT, verticalAlignment);
+ }
+
+ public static Argument<List<DocumentElement>> withChildren(DocumentElement... children) {
+ return arg(CHILDREN, asList(children));
+ }
+
+ public static Argument<Integer> withRowspan(Integer rowspan) {
+ return arg(ROWSPAN, rowspan);
+ }
+
+ public static Argument<Integer> withColspan(Integer colspan) {
+ return arg(COLSPAN, colspan);
+ }
+
+ public static Paragraph paragraph(Object... args) {
+ Arguments arguments = new Arguments(args);
+ return new Paragraph(
+ arguments.get(STYLE, Optional.empty()),
+ arguments.get(NUMBERING, Optional.empty()),
+ arguments.get(CHILDREN, list())
+ );
+ }
+
+ public static Run run(Object... args) {
+ Arguments arguments = new Arguments(args);
+ return new Run(
+ arguments.get(BOLD, false),
+ arguments.get(ITALIC, false),
+ arguments.get(UNDERLINE, false),
+ arguments.get(STRIKETHROUGH, false),
+ arguments.get(VERTICAL_ALIGNMENT, VerticalAlignment.BASELINE),
+ arguments.get(STYLE, Optional.empty()),
+ arguments.get(CHILDREN, list())
+ );
+ }
+
+ public static TableCell tableCell(Object... args) {
+ Arguments arguments = new Arguments(args);
+ return new TableCell(
+ arguments.get(ROWSPAN, 1),
+ arguments.get(COLSPAN, 1),
+ arguments.get(CHILDREN, list())
+ );
}
public static Paragraph paragraphWithText(String text) {
- return make(a(PARAGRAPH, with(CHILDREN, list(runWithText(text)))));
+ return paragraph(withChildren(runWithText(text)));
}
public static Run runWithText(String text) {
- return make(a(RUN, with(CHILDREN, list(new Text(text)))));
+ return run(withChildren(new Text(text)));
}
}
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 59f69cf..bf3c5e5 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -19,7 +19,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
-import static com.natpryce.makeiteasy.MakeItEasy.*;
import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -48,7 +47,7 @@ public class BodyXmlTests {
XmlElement element = runXml(list(textXml("Hello!")));
assertThat(
readSuccess(bodyReader(), element),
- isRun(run(text("Hello!"))));
+ isRun(run(withChildren(text("Hello!")))));
}
@Test
@@ -56,7 +55,7 @@ public class BodyXmlTests {
XmlElement element = paragraphXml(list(runXml(list(textXml("Hello!")))));
assertThat(
readSuccess(bodyReader(), element),
- isParagraph(make(a(PARAGRAPH, with(CHILDREN, list(run(text("Hello!"))))))));
+ isParagraph(paragraph(withChildren(run(withChildren(text("Hello!")))))));
}
@Test
@@ -323,7 +322,7 @@ public class BodyXmlTests {
deepEquals(new Table(list(
new TableRow(list(
new TableCell(1, 1, list(
- make(a(PARAGRAPH))
+ paragraph()
))
))
)))
@@ -345,7 +344,7 @@ public class BodyXmlTests {
deepEquals(new Table(list(
new TableRow(list(
new TableCell(1, 2, list(
- make(a(PARAGRAPH))
+ paragraph()
))
))
)))
@@ -435,7 +434,7 @@ public class BodyXmlTests {
assertThat(
read(bodyReader(), element),
isInternalResult(
- deepEquals(new Table(list(make(a(PARAGRAPH))))),
+ deepEquals(new Table(list(paragraph()))),
list("unexpected non-row element in table, cell merging may be incorrect")
)
);
@@ -450,7 +449,7 @@ public class BodyXmlTests {
assertThat(
read(bodyReader(), element),
isInternalResult(
- deepEquals(new Table(list(new TableRow(list(make(a(PARAGRAPH))))))),
+ deepEquals(new Table(list(new TableRow(list(paragraph()))))),
list("unexpected non-cell element in table row, cell merging may be incorrect")
)
);
@@ -463,7 +462,7 @@ public class BodyXmlTests {
XmlElement element = element("w:hyperlink", map("r:id", "r42"), list(runXml(list())));
assertThat(
readSuccess(bodyReader(relationships), element),
- deepEquals(Hyperlink.href("http://example.com", list(make(a(RUN))))));
+ deepEquals(Hyperlink.href("http://example.com", list(run(withChildren())))));
}
@Test
@@ -471,7 +470,7 @@ public class BodyXmlTests {
XmlElement element = element("w:hyperlink", map("w:anchor", "start"), list(runXml(list())));
assertThat(
readSuccess(bodyReader(), element),
- deepEquals(Hyperlink.anchor("start", list(make(a(RUN))))));
+ deepEquals(Hyperlink.anchor("start", list(run(withChildren())))));
}
@Test
@@ -479,7 +478,7 @@ public class BodyXmlTests {
XmlElement element = element("w:hyperlink", list(runXml(list())));
assertThat(
readSuccess(bodyReader(), element),
- deepEquals(make(a(RUN))));
+ deepEquals(run(withChildren())));
}
@Test
@@ -527,14 +526,14 @@ public class BodyXmlTests {
runXml(list(textBox, textXml("[paragragh end]")))));
List<DocumentElement> expected = list(
- make(a(PARAGRAPH, with(CHILDREN, list(
- make(a(RUN, with(CHILDREN, list(
- new Text("[paragragh start]"))))),
- make(a(RUN, with(CHILDREN, list(
- new Text("[paragragh end]"))))))))),
- make(a(PARAGRAPH, with(CHILDREN, list(
- make(a(RUN, with(CHILDREN, list(
- new Text("[textbox-content]"))))))))));
+ paragraph(withChildren(
+ run(withChildren(
+ new Text("[paragragh start]"))),
+ run(withChildren(
+ new Text("[paragragh end]"))))),
+ paragraph(withChildren(
+ run(withChildren(
+ new Text("[textbox-content]"))))));
assertThat(
readAll(bodyReader(), paragraph),
@@ -680,7 +679,7 @@ public class BodyXmlTests {
assertThat(
readSuccess(bodyReader(), element),
- deepEquals(make(a(PARAGRAPH))));
+ deepEquals(paragraph()));
}
@Test
@@ -726,7 +725,7 @@ public class BodyXmlTests {
XmlElement element = runXml(list(XmlNodes.text("[text]")));
assertThat(
readSuccess(bodyReader(), element),
- deepEquals(make(a(RUN))));
+ deepEquals(run(withChildren())));
}
private static DocumentElement readSuccess(BodyXmlReader reader, XmlElement element) {
@@ -789,10 +788,6 @@ public class BodyXmlTests {
return hasProperty("numbering", deepEquals(expected));
}
- private Run run(DocumentElement... children) {
- return make(a(RUN, with(CHILDREN, asList(children))));
- }
-
private Text text(String value) {
return new Text(value);
}
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/CommentXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/CommentXmlTests.java
index dd75ec2..6abf086 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/CommentXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/CommentXmlTests.java
@@ -9,8 +9,6 @@ import org.zwobble.mammoth.internal.xml.XmlNode;
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.hamcrest.Matchers.*;
import static org.hamcrest.core.Is.isA;
@@ -19,7 +17,7 @@ import static org.zwobble.mammoth.internal.util.Maps.map;
import static org.zwobble.mammoth.internal.xml.XmlNodes.element;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.tests.ResultMatchers.isInternalSuccess;
-import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH;
+import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.paragraph;
import static org.zwobble.mammoth.tests.docx.BodyXmlReaderMakers.bodyReader;
public class CommentXmlTests {
@@ -36,7 +34,7 @@ public class CommentXmlTests {
allOf(
isA(Comment.class),
hasProperty("commentId", equalTo("1")),
- hasProperty("body", deepEquals(list(make(a(PARAGRAPH)))))
+ hasProperty("body", deepEquals(list(paragraph())))
)
))
);
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 7e53f13..7c3670a 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/NotesXmlReaderTests.java
@@ -10,14 +10,12 @@ import org.zwobble.mammoth.internal.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.internal.util.Lists.list;
import static org.zwobble.mammoth.internal.util.Maps.map;
import static org.zwobble.mammoth.internal.xml.XmlNodes.element;
import static org.zwobble.mammoth.tests.ResultMatchers.isInternalSuccess;
-import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH;
+import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.paragraph;
import static org.zwobble.mammoth.tests.docx.BodyXmlReaderMakers.bodyReader;
public class NotesXmlReaderTests {
@@ -34,7 +32,7 @@ public class NotesXmlReaderTests {
assertThat(
notes,
- isInternalSuccess(list(new Note(NoteType.FOOTNOTE, "1", list(make(a(PARAGRAPH)))))));
+ isInternalSuccess(list(new Note(NoteType.FOOTNOTE, "1", list(paragraph())))));
}
@Test
diff --git a/src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java b/src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java
index abd195d..3f9a288 100644
--- a/src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java
@@ -8,104 +8,97 @@ import org.zwobble.mammoth.internal.styles.ParagraphMatcher;
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 org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
-import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.NUMBERING;
-import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH;
-import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.STYLE;
+import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*;
public class ParagraphMatcherTests {
@Test
public void matcherWithoutConstraintsMatchesEverything() {
- assertTrue(ParagraphMatcher.ANY.matches(make(a(PARAGRAPH))));
+ assertTrue(ParagraphMatcher.ANY.matches(paragraph()));
- Paragraph paragraphWithStyleId = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty())))));
+ Paragraph paragraphWithStyleId = paragraph(withStyle(new Style("TipsParagraph", Optional.empty())));
assertTrue(ParagraphMatcher.ANY.matches(paragraphWithStyleId));
- Paragraph paragraphWithStyleName = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("TipsParagraph", Optional.of("Tips Paragraph"))))));
+ Paragraph paragraphWithStyleName = paragraph(withStyle(new Style("TipsParagraph", Optional.of("Tips Paragraph"))));
assertTrue(ParagraphMatcher.ANY.matches(paragraphWithStyleName));
}
@Test
public void matcherWithStyleIdOnlyMatchesParagraphsWithThatStyleId() {
ParagraphMatcher matcher = ParagraphMatcher.styleId("TipsParagraph");
- assertFalse(matcher.matches(make(a(PARAGRAPH))));
+ assertFalse(matcher.matches(paragraph()));
- Paragraph paragraphWithCorrectStyleId = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty())))));
+ Paragraph paragraphWithCorrectStyleId = paragraph(
+ withStyle(new Style("TipsParagraph", Optional.empty())));
assertTrue(matcher.matches(paragraphWithCorrectStyleId));
- Paragraph paragraphWithIncorrectStyleId = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("Heading 1", Optional.empty())))));
+ Paragraph paragraphWithIncorrectStyleId = paragraph(
+ withStyle(new Style("Heading 1", Optional.empty())));
assertFalse(matcher.matches(paragraphWithIncorrectStyleId));
}
@Test
public void matcherWithStyleNameOnlyMatchesParagraphsWithThatStyleName() {
ParagraphMatcher matcher = ParagraphMatcher.styleName("Tips Paragraph");
- assertFalse(matcher.matches(make(a(PARAGRAPH))));
+ assertFalse(matcher.matches(paragraph()));
- Paragraph paragraphWithNamelessStyle = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty())))));
+ Paragraph paragraphWithNamelessStyle = paragraph(
+ withStyle(new Style("TipsParagraph", Optional.empty())));
assertFalse(matcher.matches(paragraphWithNamelessStyle));
- Paragraph paragraphWithCorrectStyleName = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("TipsParagraph", Optional.of("Tips Paragraph"))))));
+ Paragraph paragraphWithCorrectStyleName = paragraph(
+ withStyle(new Style("TipsParagraph", Optional.of("Tips Paragraph"))));
assertTrue(matcher.matches(paragraphWithCorrectStyleName));
- Paragraph paragraphWithIncorrectStyleName = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("Heading 1", Optional.of("Heading 1"))))));
+ Paragraph paragraphWithIncorrectStyleName = paragraph(
+ withStyle(new Style("Heading 1", Optional.of("Heading 1"))));
assertFalse(matcher.matches(paragraphWithIncorrectStyleName));
}
@Test
public void styleNamesAreCaseInsensitive() {
ParagraphMatcher matcher = ParagraphMatcher.styleName("tips paragraph");
- assertFalse(matcher.matches(make(a(PARAGRAPH))));
+ assertFalse(matcher.matches(paragraph()));
- Paragraph paragraphWithCorrectStyleName = make(a(PARAGRAPH,
- with(STYLE, Optional.of(new Style("TipsParagraph", Optional.of("Tips Paragraph"))))));
+ Paragraph paragraphWithCorrectStyleName = paragraph(
+ withStyle(new Style("TipsParagraph", Optional.of("Tips Paragraph"))));
assertTrue(matcher.matches(paragraphWithCorrectStyleName));
}
@Test
public void matcherWithOrderedListOnlyMatchesParagraphsWithOrderedListAtThatLeve() {
ParagraphMatcher matcher = ParagraphMatcher.orderedList("4");
- assertFalse(matcher.matches(make(a(PARAGRAPH))));
+ assertFalse(matcher.matches(paragraph()));
- Paragraph paragraphWithCorrectNumbering = make(a(PARAGRAPH,
- with(NUMBERING, Optional.of(NumberingLevel.ordered("4")))));
+ Paragraph paragraphWithCorrectNumbering = paragraph(
+ withNumbering(NumberingLevel.ordered("4")));
assertTrue(matcher.matches(paragraphWithCorrectNumbering));
- Paragraph paragraphWithIncorrectLevel = make(a(PARAGRAPH,
- with(NUMBERING, Optional.of(NumberingLevel.ordered("3")))));
+ Paragraph paragraphWithIncorrectLevel = paragraph(
+ withNumbering(NumberingLevel.ordered("3")));
assertFalse(matcher.matches(paragraphWithIncorrectLevel));
- Paragraph paragraphWithIncorrectOrdering = make(a(PARAGRAPH,
- with(NUMBERING, Optional.of(NumberingLevel.unordered("4")))));
+ Paragraph paragraphWithIncorrectOrdering = paragraph(
+ withNumbering(NumberingLevel.unordered("4")));
assertFalse(matcher.matches(paragraphWithIncorrectOrdering));
}
@Test
public void matcherWithUnorderedListOnlyMatchesParagraphsWithUnrderedListAtThatLeve() {
ParagraphMatcher matcher = ParagraphMatcher.unorderedList("4");
- assertFalse(matcher.matches(make(a(PARAGRAPH))));
+ assertFalse(matcher.matches(paragraph()));
- Paragraph paragraphWithCorrectNumbering = make(a(PARAGRAPH,
- with(NUMBERING, Optional.of(NumberingLevel.unordered("4")))));
+ Paragraph paragraphWithCorrectNumbering = paragraph(
+ withNumbering(NumberingLevel.unordered("4")));
assertTrue(matcher.matches(paragraphWithCorrectNumbering));
- Paragraph paragraphWithIncorrectLevel = make(a(PARAGRAPH,
- with(NUMBERING, Optional.of(NumberingLevel.unordered("3")))));
+ Paragraph paragraphWithIncorrectLevel = paragraph(
+ withNumbering(NumberingLevel.unordered("3")));
assertFalse(matcher.matches(paragraphWithIncorrectLevel));
- Paragraph paragraphWithIncorrectOrdering = make(a(PARAGRAPH,
- with(NUMBERING, Optional.of(NumberingLevel.ordered("4")))));
+ Paragraph paragraphWithIncorrectOrdering = paragraph(
+ withNumbering(NumberingLevel.ordered("4")));
assertFalse(matcher.matches(paragraphWithIncorrectOrdering));
}
}