From 9d5da9d5339055198aac8d0d41c3d33d97344ebd Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 21 Feb 2016 09:15:50 +0000 Subject: Handle errors when reading images --- .../java/org/zwobble/mammoth/tests/MammothTests.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/test/java/org') diff --git a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java index e778630..603d39a 100644 --- a/src/test/java/org/zwobble/mammoth/tests/MammothTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/MammothTests.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.assertThat; import static org.zwobble.mammoth.results.Result.success; import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; @@ -84,6 +85,23 @@ public class MammothTests { } } + @Test + public void warnIfImagesStoredOutsideOfDocumentAreNotFound() throws IOException { + Path tempDirectory = Files.createTempDirectory("mammoth-"); + try { + Path documentPath = tempDirectory.resolve("external-picture.docx"); + Files.copy(TestData.file("external-picture.docx").toPath(), documentPath); + assertThat( + Mammoth.convertToHtml(documentPath.toFile()), + allOf( + hasProperty("value", equalTo("")), + hasProperty("warnings", contains( + hasProperty("message", startsWith("could not open external image 'tiny-picture.png'")))))); + } finally { + tempDirectory.toFile().delete(); + } + } + @Test public void contentTypesAreRead() { assertThat( -- cgit v1.2.3