diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-03-27 19:20:19 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-03-27 19:20:19 +0100 |
| commit | 244ed7482aedf44a8afccc7b2f7f77c977974f82 (patch) | |
| tree | 9d19d3bf802de4dde5a03127a59b612e5df87f46 /src/test/java/org/zwobble | |
| parent | b1388b638a872de859d13fc348a80f1d2e2fb634 (diff) | |
Add custom image converters
Diffstat (limited to 'src/test/java/org/zwobble')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/MammothTests.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index ac81c76..393f1a7 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -3,11 +3,16 @@ package org.zwobble.mammoth.tests; import org.junit.Test; import org.zwobble.mammoth.DocumentConverter; import org.zwobble.mammoth.Result; -import org.zwobble.mammoth.internal.docx.EmbeddedStyleMap; +import org.zwobble.mammoth.images.ImageConverter; import org.zwobble.mammoth.internal.archives.InMemoryArchive; +import org.zwobble.mammoth.internal.docx.EmbeddedStyleMap; import org.zwobble.mammoth.internal.styles.parsing.ParseException; +import org.zwobble.mammoth.internal.util.Base64Encoding; -import java.io.*; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.function.Function; @@ -15,6 +20,7 @@ import java.util.function.Function; import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; import static org.zwobble.mammoth.internal.util.Lists.list; +import static org.zwobble.mammoth.internal.util.Maps.map; import static org.zwobble.mammoth.tests.ResultMatchers.isResult; import static org.zwobble.mammoth.tests.ResultMatchers.isSuccess; import static org.zwobble.mammoth.tests.util.MammothAsserts.assertThrows; @@ -132,6 +138,19 @@ public class MammothTests { } @Test + public void imageConversionCanBeCustomised() throws IOException { + ImageConverter.ImgElement imageConverter = image -> { + String base64 = Base64Encoding.streamToBase64(image::getInputStream); + String src = base64.substring(0, 2) + "," + image.getContentType(); + return map("src", src); + }; + assertThat( + convertToHtml("tiny-picture.docx", converter -> converter.imageConverter(imageConverter)), + isSuccess("<p><img src=\"iV,image/png\" /></p>") + ); + } + + @Test public void contentTypesAreRead() throws IOException { assertThat( convertToHtml("tiny-picture-custom-content-type.docx"), |
