.withText(text); | .withText(text); | ||||
} | } | ||||
/** | |||||
* Convenience method. | |||||
* Sames as {@code hasParagraph().withLines(line1, line2, ...)}. | |||||
*/ | |||||
public HtmlParagraphAssert hasParagraph(String firstLine, String... otherLines) { | |||||
return hasParagraph() | |||||
.withLines(firstLine, otherLines); | |||||
} | |||||
} | } |
return this; | return this; | ||||
} | } | ||||
public HtmlListAssert hasList() { | |||||
isNotNull(); | |||||
Assertions.assertThat(nextBlocks.hasNext()) | |||||
.describedAs("no more block") | |||||
.isTrue(); | |||||
Element element = nextBlocks.next(); | |||||
verifyIsList(element); | |||||
return new HtmlListAssert(element, nextBlocks); | |||||
} | |||||
/** | /** | ||||
* Convenience method. | * Convenience method. | ||||
* Sames as {@code hasParagraph().withText(text)}. | * Sames as {@code hasParagraph().withText(text)}. | ||||
HtmlParagraphAssert.verifyIsParagraph(element); | HtmlParagraphAssert.verifyIsParagraph(element); | ||||
return element; | return element; | ||||
} | } | ||||
/** | |||||
* Verifies there is no more list in the block. | |||||
*/ | |||||
public void noMoreBlock() { | |||||
isNotNull(); | |||||
Assertions.assertThat(nextBlocks.hasNext()) | |||||
.describedAs("there are still some block. Next one:" + PRINT_FRAGMENT_TEMPLATE, | |||||
new Object() { | |||||
@Override | |||||
public String toString() { | |||||
return nextBlocks.next().toString(); | |||||
} | |||||
}) | |||||
.isFalse(); | |||||
} | |||||
} | } |
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Iterator; | import java.util.Iterator; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | |||||
import java.util.stream.Stream; | import java.util.stream.Stream; | ||||
import org.assertj.core.api.Assertions; | import org.assertj.core.api.Assertions; | ||||
import org.jsoup.nodes.Element; | import org.jsoup.nodes.Element; | ||||
return new HtmlParagraphAssert(paragraph, nextBlocks); | return new HtmlParagraphAssert(paragraph, nextBlocks); | ||||
} | } | ||||
/** | |||||
* Convenience method. | |||||
* Sames as {@code hasParagraph().withLines(line1, line2, ...)}. | |||||
*/ | |||||
public HtmlParagraphAssert hasParagraph(String firstLine, String... otherLines) { | |||||
return hasParagraph() | |||||
.withLines(firstLine, otherLines); | |||||
} | |||||
/** | /** | ||||
* Verifies there is no more block. | * Verifies there is no more block. | ||||
*/ | */ | ||||
return this; | return this; | ||||
} | } | ||||
/** | |||||
* Verifies the current block has all and only the specified lines, in any order. | |||||
*/ | |||||
public HtmlParagraphAssert withLines(Set<String> lines) { | |||||
isNotNull(); | |||||
List<String> actualLines = toLines(actual); | |||||
String[] expectedLines = lines.toArray(new String[0]); | |||||
Assertions.assertThat(actualLines) | |||||
.describedAs(PRINT_FRAGMENT_TEMPLATE, actual) | |||||
.containsOnly(expectedLines); | |||||
return this; | |||||
} | |||||
private static List<String> toLines(Element parent) { | private static List<String> toLines(Element parent) { | ||||
Iterator<Node> iterator = parent.childNodes().iterator(); | Iterator<Node> iterator = parent.childNodes().iterator(); | ||||
if (!iterator.hasNext()) { | if (!iterator.hasNext()) { |
return this; | return this; | ||||
} | } | ||||
public MimeMessageAssert hasSubject(String text) { | |||||
isNotNull(); | |||||
try { | |||||
Assertions.assertThat(actual.getSubject()).isEqualTo(text); | |||||
} catch (MessagingException e) { | |||||
throw new IllegalStateException(e); | |||||
} | |||||
return this; | |||||
} | |||||
public MimeMessageAssert subjectContains(String text) { | public MimeMessageAssert subjectContains(String text) { | ||||
isNotNull(); | isNotNull(); | ||||