diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-02-20 15:10:45 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-02-20 15:10:45 +0000 |
| commit | 70f03f3de834bd1ce3e12e71e9809b845a41f8a4 (patch) | |
| tree | 3a732da43631ec50d9e6cf94c16a6627c57ff4b3 /src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java | |
| parent | a506a6d3679c282cfd3a2f0257f5859d420feb22 (diff) | |
Add tests for ParagraphMatcher
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java b/src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java new file mode 100644 index 0000000..8c75369 --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/styles/ParagraphMatcherTests.java @@ -0,0 +1,63 @@ +package org.zwobble.mammoth.tests.styles; + +import org.junit.Test; +import org.zwobble.mammoth.documents.Paragraph; +import org.zwobble.mammoth.documents.Style; +import org.zwobble.mammoth.styles.ParagraphMatcher; + +import java.util.Optional; + +import static com.natpryce.makeiteasy.MakeItEasy.a; +import static com.natpryce.makeiteasy.MakeItEasy.make; +import static com.natpryce.makeiteasy.MakeItEasy.with; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.PARAGRAPH; +import static org.zwobble.mammoth.tests.documents.DocumentElementMakers.STYLE; + +public class ParagraphMatcherTests { + @Test + public void matcherWithoutConstraintsMatchesEverything() { + assertTrue(ParagraphMatcher.ANY.matches(make(a(PARAGRAPH)))); + + Paragraph paragraphWithStyleId = make(a(PARAGRAPH, + with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty()))))); + assertTrue(ParagraphMatcher.ANY.matches(paragraphWithStyleId)); + + Paragraph paragraphWithStyleName = make(a(PARAGRAPH, + with(STYLE, Optional.of(new Style("TipsParagraph", Optional.of("Tips Paragraph")))))); + assertTrue(ParagraphMatcher.ANY.matches(paragraphWithStyleName)); + } + + @Test + public void matcherWithStyleIdOnlyMatchesParagraphsWithThatStyleId() { + ParagraphMatcher matcher = ParagraphMatcher.styleId("TipsParagraph"); + assertFalse(matcher.matches(make(a(PARAGRAPH)))); + + Paragraph paragraphWithCorrectStyleId = make(a(PARAGRAPH, + with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty()))))); + assertTrue(matcher.matches(paragraphWithCorrectStyleId)); + + Paragraph paragraphWithIncorrectStyleId = make(a(PARAGRAPH, + with(STYLE, Optional.of(new Style("Heading 1", Optional.empty()))))); + assertFalse(matcher.matches(paragraphWithIncorrectStyleId)); + } + + @Test + public void matcherWithStyleNameOnlyMatchesParagraphsWithThatStyleName() { + ParagraphMatcher matcher = ParagraphMatcher.styleName("Tips Paragraph"); + assertFalse(matcher.matches(make(a(PARAGRAPH)))); + + Paragraph paragraphWithNamelessStyle = make(a(PARAGRAPH, + with(STYLE, Optional.of(new Style("TipsParagraph", Optional.empty()))))); + assertFalse(matcher.matches(paragraphWithNamelessStyle)); + + Paragraph paragraphWithCorrectStyleName = make(a(PARAGRAPH, + with(STYLE, Optional.of(new Style("TipsParagraph", Optional.of("Tips Paragraph")))))); + assertTrue(matcher.matches(paragraphWithCorrectStyleName)); + + Paragraph paragraphWithIncorrectStyleName = make(a(PARAGRAPH, + with(STYLE, Optional.of(new Style("Heading 1", Optional.of("Heading 1")))))); + assertFalse(matcher.matches(paragraphWithIncorrectStyleName)); + } +} |
