summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-24 21:56:31 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-24 23:24:20 +0000
commit56dad2617a86aeb83cf4f7f56519af621979851d (patch)
tree618e572381fa70f868a03e020c61b38fee4b8028
parentcc66aa555d68eb33dfceb052e5dc37284e5080bd (diff)
Use Set instead of List for warnings
-rw-r--r--src/main/java/org/zwobble/mammoth/DocumentConverter.java9
-rw-r--r--src/main/java/org/zwobble/mammoth/Result.java4
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/DocumentToHtml.java3
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/DocumentToHtmlOptions.java19
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java4
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/docx/ReadResult.java18
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/results/InternalResult.java22
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/util/MammothSets.java15
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java45
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java5
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/MammothTests.java11
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/ResultMatchers.java21
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java16
13 files changed, 144 insertions, 48 deletions
diff --git a/src/main/java/org/zwobble/mammoth/DocumentConverter.java b/src/main/java/org/zwobble/mammoth/DocumentConverter.java
index 76c1901..e11ec8b 100644
--- a/src/main/java/org/zwobble/mammoth/DocumentConverter.java
+++ b/src/main/java/org/zwobble/mammoth/DocumentConverter.java
@@ -12,9 +12,8 @@ import org.zwobble.mammoth.internal.docx.DocxFile;
import org.zwobble.mammoth.internal.docx.InMemoryDocxFile;
import org.zwobble.mammoth.internal.docx.ZippedDocxFile;
import org.zwobble.mammoth.internal.html.Html;
-import org.zwobble.mammoth.internal.styles.DefaultStyles;
-import org.zwobble.mammoth.internal.util.Casts;
import org.zwobble.mammoth.internal.results.InternalResult;
+import org.zwobble.mammoth.internal.util.Casts;
import java.io.File;
import java.io.IOException;
@@ -31,7 +30,7 @@ public class DocumentConverter {
private final DocumentToHtmlOptions options;
public DocumentConverter() {
- this(DocumentToHtmlOptions.DEFAULT.addStyleMap(DefaultStyles.DEFAULT_STYLE_MAP));
+ this(DocumentToHtmlOptions.DEFAULT);
}
private DocumentConverter(DocumentToHtmlOptions options) {
@@ -50,6 +49,10 @@ public class DocumentConverter {
return new DocumentConverter(options.addStyleMap(styleMap));
}
+ public DocumentConverter disableDefaultStyleMap() {
+ return new DocumentConverter(options.disableDefaultStyleMap());
+ }
+
public Result<String> convertToHtml(InputStream stream) throws IOException {
return withDocxFile(stream, zipFile ->
convertToHtml(Optional.empty(), zipFile));
diff --git a/src/main/java/org/zwobble/mammoth/Result.java b/src/main/java/org/zwobble/mammoth/Result.java
index 2660fd4..1c09559 100644
--- a/src/main/java/org/zwobble/mammoth/Result.java
+++ b/src/main/java/org/zwobble/mammoth/Result.java
@@ -1,8 +1,8 @@
package org.zwobble.mammoth;
-import java.util.List;
+import java.util.Set;
public interface Result<T> {
T getValue();
- List<String> getWarnings();
+ Set<String> getWarnings();
}
diff --git a/src/main/java/org/zwobble/mammoth/internal/DocumentToHtml.java b/src/main/java/org/zwobble/mammoth/internal/DocumentToHtml.java
index 45ff92e..16210cd 100644
--- a/src/main/java/org/zwobble/mammoth/internal/DocumentToHtml.java
+++ b/src/main/java/org/zwobble/mammoth/internal/DocumentToHtml.java
@@ -2,6 +2,7 @@ package org.zwobble.mammoth.internal;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.io.ByteStreams;
import org.zwobble.mammoth.internal.documents.*;
@@ -47,7 +48,7 @@ public class DocumentToHtml {
private final boolean preserveEmptyParagraphs;
private final StyleMap styleMap;
private final List<NoteReference> noteReferences = new ArrayList<>();
- private final ImmutableList.Builder<String> warnings = ImmutableList.builder();
+ private final ImmutableSet.Builder<String> warnings = ImmutableSet.builder();
private DocumentToHtml(DocumentToHtmlOptions options) {
this.idPrefix = options.idPrefix();
diff --git a/src/main/java/org/zwobble/mammoth/internal/DocumentToHtmlOptions.java b/src/main/java/org/zwobble/mammoth/internal/DocumentToHtmlOptions.java
index 4cd6372..05218a9 100644
--- a/src/main/java/org/zwobble/mammoth/internal/DocumentToHtmlOptions.java
+++ b/src/main/java/org/zwobble/mammoth/internal/DocumentToHtmlOptions.java
@@ -1,27 +1,30 @@
package org.zwobble.mammoth.internal;
+import org.zwobble.mammoth.internal.styles.DefaultStyles;
import org.zwobble.mammoth.internal.styles.StyleMap;
import org.zwobble.mammoth.internal.styles.parsing.StyleMapParser;
public class DocumentToHtmlOptions {
- public static final DocumentToHtmlOptions DEFAULT = new DocumentToHtmlOptions("", false, StyleMap.EMPTY);
+ public static final DocumentToHtmlOptions DEFAULT = new DocumentToHtmlOptions("", false, StyleMap.EMPTY, false);
private final String idPrefix;
private final boolean preserveEmptyParagraphs;
private final StyleMap styleMap;
+ private final boolean disableDefaultStyleMap;
- public DocumentToHtmlOptions(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap) {
+ public DocumentToHtmlOptions(String idPrefix, boolean preserveEmptyParagraphs, StyleMap styleMap, boolean disableDefaultStyleMap) {
this.idPrefix = idPrefix;
this.preserveEmptyParagraphs = preserveEmptyParagraphs;
this.styleMap = styleMap;
+ this.disableDefaultStyleMap = disableDefaultStyleMap;
}
public DocumentToHtmlOptions idPrefix(String prefix) {
- return new DocumentToHtmlOptions(prefix, preserveEmptyParagraphs, styleMap);
+ return new DocumentToHtmlOptions(prefix, preserveEmptyParagraphs, styleMap, disableDefaultStyleMap);
}
public DocumentToHtmlOptions preserveEmptyParagraphs() {
- return new DocumentToHtmlOptions(idPrefix, true, styleMap);
+ return new DocumentToHtmlOptions(idPrefix, true, styleMap, disableDefaultStyleMap);
}
public DocumentToHtmlOptions addStyleMap(String styleMap) {
@@ -29,7 +32,11 @@ public class DocumentToHtmlOptions {
}
public DocumentToHtmlOptions addStyleMap(StyleMap styleMap) {
- return new DocumentToHtmlOptions(idPrefix, preserveEmptyParagraphs, this.styleMap.update(styleMap));
+ return new DocumentToHtmlOptions(idPrefix, preserveEmptyParagraphs, this.styleMap.update(styleMap), disableDefaultStyleMap);
+ }
+
+ public DocumentToHtmlOptions disableDefaultStyleMap() {
+ return new DocumentToHtmlOptions(idPrefix, preserveEmptyParagraphs, styleMap, true);
}
public String idPrefix() {
@@ -41,6 +48,6 @@ public class DocumentToHtmlOptions {
}
public StyleMap styleMap() {
- return styleMap;
+ return disableDefaultStyleMap ? styleMap : DefaultStyles.DEFAULT_STYLE_MAP.update(styleMap);
}
}
diff --git a/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java b/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java
index 0edc7a7..9951cbc 100644
--- a/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java
+++ b/src/main/java/org/zwobble/mammoth/internal/docx/BodyXmlReader.java
@@ -18,7 +18,7 @@ import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static org.zwobble.mammoth.internal.docx.ReadResult.EMPTY_SUCCESS;
import static org.zwobble.mammoth.internal.docx.ReadResult.success;
-import static org.zwobble.mammoth.internal.util.MammothLists.list;
+import static org.zwobble.mammoth.internal.util.MammothSets.set;
import static org.zwobble.mammoth.internal.util.MammothStrings.trimLeft;
public class BodyXmlReader {
@@ -213,7 +213,7 @@ public class BodyXmlReader {
} else {
return new InternalResult<>(
Optional.of(new Style(styleId, Optional.empty())),
- list(styleType + " style with ID " + styleId + " was referenced but not defined in the document"));
+ set(styleType + " style with ID " + styleId + " was referenced but not defined in the document"));
}
}
diff --git a/src/main/java/org/zwobble/mammoth/internal/docx/ReadResult.java b/src/main/java/org/zwobble/mammoth/internal/docx/ReadResult.java
index b390649..8f3053d 100644
--- a/src/main/java/org/zwobble/mammoth/internal/docx/ReadResult.java
+++ b/src/main/java/org/zwobble/mammoth/internal/docx/ReadResult.java
@@ -1,14 +1,18 @@
package org.zwobble.mammoth.internal.docx;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
import org.zwobble.mammoth.internal.documents.DocumentElement;
import org.zwobble.mammoth.internal.results.InternalResult;
import java.util.List;
+import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import static org.zwobble.mammoth.internal.util.MammothLists.list;
+import static org.zwobble.mammoth.internal.util.MammothSets.set;
public class ReadResult {
public static final ReadResult EMPTY_SUCCESS = success(list());
@@ -16,7 +20,7 @@ public class ReadResult {
public static ReadResult concat(Iterable<ReadResult> results) {
ImmutableList.Builder<DocumentElement> elements = ImmutableList.builder();
ImmutableList.Builder<DocumentElement> extra = ImmutableList.builder();
- ImmutableList.Builder<String> warnings = ImmutableList.builder();
+ ImmutableSet.Builder<String> warnings = ImmutableSet.builder();
for (ReadResult result : results) {
elements.addAll(result.elements);
extra.addAll(result.extra);
@@ -33,7 +37,7 @@ public class ReadResult {
return new ReadResult(
list(function.apply(first.getValue(), second.elements)),
second.extra,
- concat(first.getWarnings(), second.warnings));
+ Sets.union(first.getWarnings(), second.warnings).immutableCopy());
}
public static ReadResult success(DocumentElement element) {
@@ -41,22 +45,22 @@ public class ReadResult {
}
public static ReadResult success(List<DocumentElement> elements) {
- return new ReadResult(elements, list(), list());
+ return new ReadResult(elements, list(), set());
}
public static ReadResult emptyWithWarning(String warning) {
- return new ReadResult(list(), list(), list(warning));
+ return new ReadResult(list(), list(), set(warning));
}
public static ReadResult withWarning(DocumentElement element, String warning) {
- return new ReadResult(list(element), list(), list(warning));
+ return new ReadResult(list(element), list(), set(warning));
}
private final List<DocumentElement> elements;
private final List<DocumentElement> extra;
- private final List<String> warnings;
+ private final Set<String> warnings;
- public ReadResult(List<DocumentElement> elements, List<DocumentElement> extra, List<String> warnings) {
+ public ReadResult(List<DocumentElement> elements, List<DocumentElement> extra, Set<String> warnings) {
this.elements = elements;
this.extra = extra;
this.warnings = warnings;
diff --git a/src/main/java/org/zwobble/mammoth/internal/results/InternalResult.java b/src/main/java/org/zwobble/mammoth/internal/results/InternalResult.java
index 279692b..6ca3377 100644
--- a/src/main/java/org/zwobble/mammoth/internal/results/InternalResult.java
+++ b/src/main/java/org/zwobble/mammoth/internal/results/InternalResult.java
@@ -1,20 +1,22 @@
package org.zwobble.mammoth.internal.results;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Sets;
import org.zwobble.mammoth.internal.documents.Style;
-import org.zwobble.mammoth.internal.util.MammothLists;
import java.util.List;
import java.util.Optional;
+import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
-import static org.zwobble.mammoth.internal.util.MammothLists.list;
+import static org.zwobble.mammoth.internal.util.MammothSets.set;
public class InternalResult<T> implements org.zwobble.mammoth.Result<T> {
public static <T> InternalResult<List<T>> concat(Iterable<InternalResult<T>> results) {
ImmutableList.Builder<T> elements = ImmutableList.builder();
- ImmutableList.Builder<String> warnings = ImmutableList.builder();
+ ImmutableSet.Builder<String> warnings = ImmutableSet.builder();
for (InternalResult<T> result : results) {
elements.add(result.value);
warnings.addAll(result.warnings);
@@ -29,21 +31,21 @@ public class InternalResult<T> implements org.zwobble.mammoth.Result<T> {
{
return new InternalResult<>(
function.apply(first.value, second.value),
- MammothLists.concat(first.warnings, second.warnings));
+ Sets.union(first.warnings, second.warnings).immutableCopy());
}
public static InternalResult<Optional<Style>> empty() {
- return new InternalResult<>(Optional.empty(), list());
+ return new InternalResult<>(Optional.empty(), set());
}
public static <T> InternalResult<T> success(T value) {
- return new InternalResult<>(value, list());
+ return new InternalResult<>(value, set());
}
private final T value;
- private final List<String> warnings;
+ private final Set<String> warnings;
- public InternalResult(T value, List<String> warnings) {
+ public InternalResult(T value, Set<String> warnings) {
this.value = value;
this.warnings = warnings;
}
@@ -52,7 +54,7 @@ public class InternalResult<T> implements org.zwobble.mammoth.Result<T> {
return value;
}
- public List<String> getWarnings() {
+ public Set<String> getWarnings() {
return warnings;
}
@@ -64,6 +66,6 @@ public class InternalResult<T> implements org.zwobble.mammoth.Result<T> {
InternalResult<R> intermediateResult = function.apply(value);
return new InternalResult<>(
intermediateResult.value,
- MammothLists.concat(warnings, intermediateResult.warnings));
+ Sets.union(warnings, intermediateResult.warnings).immutableCopy());
}
}
diff --git a/src/main/java/org/zwobble/mammoth/internal/util/MammothSets.java b/src/main/java/org/zwobble/mammoth/internal/util/MammothSets.java
new file mode 100644
index 0000000..a9658ce
--- /dev/null
+++ b/src/main/java/org/zwobble/mammoth/internal/util/MammothSets.java
@@ -0,0 +1,15 @@
+package org.zwobble.mammoth.internal.util;
+
+import com.google.common.collect.ImmutableSet;
+
+import java.util.Set;
+
+public class MammothSets {
+ public static <T> Set<T> set() {
+ return ImmutableSet.of();
+ }
+
+ public static <T> Set<T> set(T value1) {
+ return ImmutableSet.of(value1);
+ }
+}
diff --git a/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java b/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java
index 72a6529..8538534 100644
--- a/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java
+++ b/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java
@@ -4,17 +4,16 @@ import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.Matchers;
-import org.hamcrest.TypeSafeDiagnosingMatcher;
+import org.hamcrest.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+import static com.google.common.collect.Iterables.any;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static java.util.Arrays.asList;
@@ -35,11 +34,20 @@ public class DeepReflectionMatcher<T> extends TypeSafeDiagnosingMatcher<T> {
return matchesSafely("", expected, item, mismatchDescription);
}
+ private static boolean deepEquals(Object expected, Object actual) {
+ Description description = new Description.NullDescription();
+ return matchesSafely("", expected, actual, description);
+ }
+
private static <T> boolean matchesSafely(String path, T expected, T actual, Description mismatchDescription) {
if (expected instanceof List && actual instanceof List) {
return matchesList(path, (List)expected, (List)actual, mismatchDescription);
}
+ if (expected instanceof Set && actual instanceof Set) {
+ return matchesSet(path, (Set)expected, (Set)actual, mismatchDescription);
+ }
+
if (expected instanceof Map && actual instanceof Map) {
return matchesMap(path, (Map)expected, (Map)actual, mismatchDescription);
}
@@ -89,6 +97,32 @@ public class DeepReflectionMatcher<T> extends TypeSafeDiagnosingMatcher<T> {
return true;
}
+ private static <T> boolean matchesSet(String path, Set<?> expected, Set<?> actual, Description mismatchDescription) {
+ List<?> missing = ImmutableList.copyOf(filter(
+ expected,
+ expectedElement -> !any(actual, actualElement -> deepEquals(expectedElement, actualElement))));
+
+ if (!missing.isEmpty()) {
+ appendPath(mismatchDescription, path);
+ mismatchDescription.appendText("missing elements:" +
+ indentedList(transform(missing, DeepReflectionMatcher::describeValue)));
+ return false;
+ }
+
+ List<?> extra = ImmutableList.copyOf(filter(
+ actual,
+ actualElement -> !any(expected, expectedElement -> deepEquals(expectedElement, actualElement))));
+
+ if (!extra.isEmpty()) {
+ appendPath(mismatchDescription, path);
+ mismatchDescription.appendText("extra elements:" +
+ indentedList(transform(extra, DeepReflectionMatcher::describeValue)));
+ return false;
+ }
+
+ return true;
+ }
+
private static <T> boolean matchesMap(String path, Map<?, ?> expected, Map<?, ?> actual, Description mismatchDescription) {
if (!handleExtraElements(path, expected, actual, mismatchDescription, "extra elements:")) {
return false;
@@ -172,6 +206,9 @@ public class DeepReflectionMatcher<T> extends TypeSafeDiagnosingMatcher<T> {
} else if (value instanceof List) {
List<?> list = (List)value;
return "[" + indentedList(transform(list, DeepReflectionMatcher::describeValue)) + "]";
+ } else if (value instanceof Set) {
+ Set<?> list = (Set)value;
+ return "{" + indentedList(transform(list, DeepReflectionMatcher::describeValue)) + "}";
} else if (value instanceof Map) {
Map<?, ?> map = (Map)value;
String entries = indentedList(
diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
index befba22..aa89eb8 100644
--- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java
@@ -24,6 +24,7 @@ import static org.zwobble.mammoth.internal.documents.VerticalAlignment.SUPERSCRI
import static org.zwobble.mammoth.internal.results.InternalResult.success;
import static org.zwobble.mammoth.internal.util.MammothLists.list;
import static org.zwobble.mammoth.internal.util.MammothMaps.map;
+import static org.zwobble.mammoth.internal.util.MammothSets.set;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*;
@@ -79,7 +80,7 @@ public class DocumentConverterTests {
deepEquals(new InternalResult<>(
list(Html.element("p")),
- list("Unrecognised paragraph style: Tips Paragraph (Style ID: TipsParagraph)"))));
+ set("Unrecognised paragraph style: Tips Paragraph (Style ID: TipsParagraph)"))));
}
@Test
@@ -106,7 +107,7 @@ public class DocumentConverterTests {
deepEquals(new InternalResult<>(
list(Html.text("Hello")),
- list("Unrecognised run style: Tips Run (Style ID: TipsRun)"))));
+ set("Unrecognised run style: Tips Run (Style ID: TipsRun)"))));
}
@Test
diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
index bc997a2..3319ebb 100644
--- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java
@@ -13,7 +13,9 @@ import java.util.function.Function;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.zwobble.mammoth.internal.results.InternalResult.success;
+import static org.zwobble.mammoth.internal.util.MammothLists.list;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
+import static org.zwobble.mammoth.tests.ResultMatchers.isResult;
public class MammothTests {
@Test
@@ -189,6 +191,15 @@ public class MammothTests {
}
@Test
+ public void canDisableDefaultStyleMap() throws IOException {
+ assertThat(
+ convertToHtml("simple-list.docx", mammoth -> mammoth.disableDefaultStyleMap()),
+ isResult(
+ equalTo("<p>Apple</p><p>Banana</p>"),
+ list("Unrecognised paragraph style: List Paragraph (Style ID: ListParagraph)")));
+ }
+
+ @Test
public void canExtractRawText() throws IOException {
assertThat(
new DocumentConverter().extractRawText(TestData.file("simple-list.docx")),
diff --git a/src/test/java/org/zwobble/mammoth/tests/ResultMatchers.java b/src/test/java/org/zwobble/mammoth/tests/ResultMatchers.java
new file mode 100644
index 0000000..a5b9585
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/ResultMatchers.java
@@ -0,0 +1,21 @@
+package org.zwobble.mammoth.tests;
+
+import com.google.common.collect.ImmutableSet;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.zwobble.mammoth.Result;
+
+import static org.hamcrest.Matchers.hasProperty;
+import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
+
+public class ResultMatchers {
+ public static Matcher<Result<?>> isResult(Matcher<?> valueMatcher, Iterable<String> warnings) {
+ return Matchers.allOf(
+ hasProperty("value", valueMatcher),
+ hasWarnings(warnings));
+ }
+
+ public static Matcher<Result<?>> hasWarnings(Iterable<String> warnings) {
+ return hasProperty("warnings", deepEquals(ImmutableSet.copyOf(warnings)));
+ }
+}
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 049db81..3141620 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -23,12 +23,12 @@ 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.allOf;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.hasProperty;
+import static org.hamcrest.Matchers.*;
import static org.zwobble.mammoth.internal.documents.NoteReference.endnoteReference;
import static org.zwobble.mammoth.internal.documents.NoteReference.footnoteReference;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
+import static org.zwobble.mammoth.tests.ResultMatchers.hasWarnings;
+import static org.zwobble.mammoth.tests.ResultMatchers.isResult;
import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*;
import static org.zwobble.mammoth.tests.docx.BodyXmlReaderMakers.*;
import static org.zwobble.mammoth.tests.docx.BodyXmlReaderMakers.NUMBERING;
@@ -475,7 +475,7 @@ public class BodyXmlTests {
assertThat(
result,
- hasProperty("warnings", deepEquals(list("Image of type image/x-emf is unlikely to display in web browsers"))));
+ hasWarnings(list("Image of type image/x-emf is unlikely to display in web browsers")));
}
@Test
@@ -594,7 +594,7 @@ public class BodyXmlTests {
private static DocumentElement readSuccess(Maker<BodyXmlReader> reader, XmlElement element) {
InternalResult<DocumentElement> result = read(reader, element);
- assertThat(result.getWarnings(), deepEquals(list()));
+ assertThat(result.getWarnings(), emptyIterable());
return result.getValue();
}
@@ -652,12 +652,6 @@ public class BodyXmlTests {
return hasProperty("numbering", deepEquals(expected));
}
- private <T> Matcher<InternalResult<? extends T>> isResult(Matcher<T> valueMatcher, List<String> warnings) {
- return Matchers.allOf(
- hasProperty("value", valueMatcher),
- hasProperty("warnings", deepEquals(warnings)));
- }
-
private Run run(DocumentElement... children) {
return make(a(RUN, with(CHILDREN, asList(children))));
}