diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-02-20 15:39:19 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-02-20 15:39:19 +0000 |
| commit | f61e177abb96034353572e5c32df0a8ae671a4d5 (patch) | |
| tree | 79a22edadba693c3c931535af8938056ac658b78 /src/test/java | |
| parent | 7ecf37adc3faff67781bdf46e624b54a35da9a54 (diff) | |
Produce warnings for unrecognised styles
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java | 22 | ||||
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/documents/StyleTests.java | 22 |
2 files changed, 43 insertions, 1 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java index 429df1e..bc37ad9 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java @@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.*; import static org.zwobble.mammoth.documents.VerticalAlignment.SUBSCRIPT; import static org.zwobble.mammoth.documents.VerticalAlignment.SUPERSCRIPT; import static org.zwobble.mammoth.results.Result.success; +import static org.zwobble.mammoth.results.Warning.warning; import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.*; import static org.zwobble.mammoth.util.MammothLists.list; @@ -69,6 +70,17 @@ public class DocumentConverterTests { } @Test + public void warningIfParagraphHasUnrecognisedStyle() { + assertThat( + convertToHtmlResult( + make(a(PARAGRAPH, with(STYLE, Optional.of(new Style("TipsParagraph", Optional.of("Tips Paragraph"))))))), + + deepEquals(new Result<>( + list(Html.element("p")), + list(warning("Unrecognised paragraph style: Tips Paragraph (Style ID: TipsParagraph)"))))); + } + + @Test public void boldRunsAreWrappedInStrongTags() { assertThat( convertToHtml(make(a(RUN, with(BOLD, true), with(CHILDREN, list(new Text("Hello")))))), @@ -256,8 +268,16 @@ public class DocumentConverterTests { } private List<HtmlNode> convertToHtml(DocumentElement element, StyleMap styleMap) { - Result<List<HtmlNode>> result = DocumentConverter.convertToHtml("doc-42-", false, styleMap, element); + Result<List<HtmlNode>> result = convertToHtmlResult(element, styleMap); assertThat(result.getWarnings(), hasSize(0)); return result.getValue(); } + + private Result<List<HtmlNode>> convertToHtmlResult(DocumentElement element) { + return convertToHtmlResult(element, StyleMap.EMPTY); + } + + private Result<List<HtmlNode>> convertToHtmlResult(DocumentElement element, StyleMap styleMap) { + return DocumentConverter.convertToHtml("doc-42-", false, styleMap, element); + } } diff --git a/src/test/java/org/zwobble/mammoth/tests/documents/StyleTests.java b/src/test/java/org/zwobble/mammoth/tests/documents/StyleTests.java new file mode 100644 index 0000000..68b07c6 --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/documents/StyleTests.java @@ -0,0 +1,22 @@ +package org.zwobble.mammoth.tests.documents; + +import org.junit.Test; +import org.zwobble.mammoth.documents.Style; + +import java.util.Optional; + +import static org.junit.Assert.assertEquals; + +public class StyleTests { + @Test + public void descriptionOfStyleIncludesBothIdAndNameIfPresent() { + Style style = new Style("Heading1", Optional.of("Heading 1")); + assertEquals("Heading 1 (Style ID: Heading1)", style.describe()); + } + + @Test + public void descriptionOfStyleIsJustStyleIdIfStyleNameIsMissing() { + Style style = new Style("Heading1", Optional.empty()); + assertEquals("Style ID: Heading1", style.describe()); + } +} |
