From 05ff9e63fb5ab95e20ebe403755ebfb1f8780c25 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 24 Feb 2016 08:32:15 +0000 Subject: Turn Mammoth into a non-static class --- .../mammoth/tests/DocumentConverterTests.java | 13 ++++++++++--- .../org/zwobble/mammoth/tests/MammothTests.java | 21 +++++++++++---------- 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/test/java/org') diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java index 40b6d99..4c40800 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java @@ -2,6 +2,7 @@ package org.zwobble.mammoth.tests; import org.junit.Test; import org.zwobble.mammoth.internal.DocumentConverter; +import org.zwobble.mammoth.internal.DocumentToHtmlOptions; import org.zwobble.mammoth.internal.documents.*; import org.zwobble.mammoth.internal.html.Html; import org.zwobble.mammoth.internal.html.HtmlNode; @@ -39,8 +40,9 @@ public class DocumentConverterTests { @Test public void forceWriteIsInsertedIntoParagraphIfEmptyParagraphsShouldBePreserved() { + DocumentToHtmlOptions options = DocumentToHtmlOptions.DEFAULT.preserveEmptyParagraphs(); assertThat( - DocumentConverter.convertToHtml("", true, StyleMap.EMPTY, make(a(PARAGRAPH))), + DocumentConverter.convertToHtml(make(a(PARAGRAPH)), options), deepEquals(success(list(Html.element("p", list(Html.FORCE_WRITE)))))); } @@ -286,7 +288,9 @@ public class DocumentConverterTests { } private List convertToHtml(Document document) { - Result> result = DocumentConverter.convertToHtml("doc-42-", false, StyleMap.EMPTY, document); + DocumentToHtmlOptions options = DocumentToHtmlOptions.DEFAULT + .idPrefix("doc-42-"); + Result> result = DocumentConverter.convertToHtml(document, options); assertThat(result.getWarnings(), hasSize(0)); return result.getValue(); } @@ -306,6 +310,9 @@ public class DocumentConverterTests { } private Result> convertToHtmlResult(DocumentElement element, StyleMap styleMap) { - return DocumentConverter.convertToHtml("doc-42-", false, styleMap, element); + DocumentToHtmlOptions options = DocumentToHtmlOptions.DEFAULT + .idPrefix("doc-42-") + .styleMap(styleMap); + return DocumentConverter.convertToHtml(element, options); } } diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index 52efde2..6e5794a 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -8,6 +8,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.function.Function; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; @@ -39,7 +40,7 @@ public class MammothTests { @Test public void emptyParagraphsArePreservedIfIgnoreEmptyParagraphsIsFalse() throws IOException { assertThat( - convertToHtml("empty.docx", Mammoth.Options.DEFAULT.preserveEmptyParagraphs()), + convertToHtml("empty.docx", mammoth -> mammoth.preserveEmptyParagraphs()), deepEquals(success("

"))); } @@ -78,7 +79,7 @@ public class MammothTests { Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); Files.copy(TestData.file("tiny-picture.png").toPath(), tempDirectory.resolve("tiny-picture.png")); assertThat( - Mammoth.convertToHtml(documentPath.toFile()), + new Mammoth().convertToHtml(documentPath.toFile()), deepEquals(success("

"))); } finally { tempDirectory.toFile().delete(); @@ -92,7 +93,7 @@ public class MammothTests { Path documentPath = tempDirectory.resolve("external-picture.docx"); Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); assertThat( - Mammoth.convertToHtml(documentPath.toUri().toURL().openStream()), + new Mammoth().convertToHtml(documentPath.toUri().toURL().openStream()), allOf( hasProperty("value", equalTo("")), hasProperty("warnings", contains( @@ -109,7 +110,7 @@ public class MammothTests { Path documentPath = tempDirectory.resolve("external-picture.docx"); Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); assertThat( - Mammoth.convertToHtml(documentPath.toFile()), + new Mammoth().convertToHtml(documentPath.toFile()), allOf( hasProperty("value", equalTo("")), hasProperty("warnings", contains( @@ -129,7 +130,7 @@ public class MammothTests { @Test public void footnotesAreAppendedToText() throws IOException { assertThat( - convertToHtml("footnotes.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")), + convertToHtml("footnotes.docx", mammoth -> mammoth.idPrefix("doc-42-")), deepEquals(success( "

Ouch" + "[1]." + @@ -141,7 +142,7 @@ public class MammothTests { @Test public void endNotesAreAppendedToText() throws IOException { assertThat( - convertToHtml("endnotes.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")), + convertToHtml("endnotes.docx", mammoth -> mammoth.idPrefix("doc-42-")), deepEquals(success( "

Ouch" + "[1]." + @@ -153,7 +154,7 @@ public class MammothTests { @Test public void relationshipsAreReadForEachFileContainingBodyXml() throws IOException { assertThat( - convertToHtml("footnote-hyperlink.docx", Mammoth.Options.DEFAULT.idPrefix("doc-42-")), + convertToHtml("footnote-hyperlink.docx", mammoth -> mammoth.idPrefix("doc-42-")), deepEquals(success( "

[1]

" + "
  1. Example ↑

"))); @@ -175,11 +176,11 @@ public class MammothTests { private Result convertToHtml(String name) throws IOException { File file = TestData.file(name); - return Mammoth.convertToHtml(file); + return new Mammoth().convertToHtml(file); } - private Result convertToHtml(String name, Mammoth.Options options) throws IOException { + private Result convertToHtml(String name, Function configure) throws IOException { File file = TestData.file(name); - return Mammoth.convertToHtml(file, options); + return configure.apply(new Mammoth()).convertToHtml(file); } } -- cgit v1.2.3