From a82d898bc1c6901749f89a905e63c9e511baae84 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 14 Feb 2016 12:58:58 +0000 Subject: Include alt text for images if available --- .../org/zwobble/mammoth/tests/DocumentConverterTests.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/test') diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java index 9287f74..3ae5d16 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java @@ -12,6 +12,9 @@ import java.util.Optional; import static com.natpryce.makeiteasy.MakeItEasy.*; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasEntry; +import static org.hamcrest.Matchers.hasProperty; import static org.zwobble.mammoth.documents.VerticalAlignment.SUBSCRIPT; import static org.zwobble.mammoth.documents.VerticalAlignment.SUPERSCRIPT; import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; @@ -149,6 +152,17 @@ public class DocumentConverterTests { deepEquals(list(Html.selfClosingElement("img", map("src", "data:image/png;base64,YWJj"))))); } + @Test + public void imagesHaveAltTagsIfAvailable() { + Image image = new Image( + Optional.of("It's a hat"), + Optional.of("image/png"), + () -> new ByteArrayInputStream(new byte[]{97, 98, 99})); + assertThat( + convertToHtml(image), + contains(hasProperty("attributes", hasEntry("alt", "It's a hat")))); + } + private List convertToHtml(DocumentElement element) { return documentConverter().convertToHtml(element); } -- cgit v1.2.3