1 package net.pterodactylus.rhynodge.filters.comics;
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.contains;
6 import java.io.IOException;
7 import java.util.Objects;
9 import net.pterodactylus.rhynodge.Filter;
10 import net.pterodactylus.rhynodge.filters.ResourceLoader;
11 import net.pterodactylus.rhynodge.states.ComicState;
12 import net.pterodactylus.rhynodge.states.ComicState.Comic;
13 import net.pterodactylus.rhynodge.states.ComicState.Strip;
14 import net.pterodactylus.rhynodge.states.HtmlState;
16 import org.hamcrest.Description;
17 import org.hamcrest.Matcher;
18 import org.hamcrest.TypeSafeDiagnosingMatcher;
19 import org.jsoup.nodes.Document;
20 import org.junit.Test;
23 * Unit test for {@link ScandinaviaAndTheWorldComicFilterTest}.
25 * @author <a href="mailto:david.roden@bietr.de">David Roden</a>
27 public class ScandinaviaAndTheWorldComicFilterTest {
29 private final Filter satwFilter = new ScandinaviaAndTheWorldComicFilter();
30 private final HtmlState htmlState;
32 public ScandinaviaAndTheWorldComicFilterTest() throws IOException {
33 Document document = ResourceLoader.loadDocument(ScandinaviaAndTheWorldComicFilter.class, "scandinavia-and-the-world.html",
34 "https://satwcomic.com/latest");
35 htmlState = new HtmlState("https://satwcomic.com/latest", document);
39 public void comicIsParsedCorrectly() {
40 ComicState comicState = (ComicState) satwFilter.filter(htmlState);
41 assertThat(comicState.comics(), contains(
42 isComic("The whale in the room", contains(
43 isStrip("http://satwcomic.com/art/the-whale-in-the-room.png", "")
48 private Matcher<? super Comic> isComic(String title, Matcher<Iterable<? extends Strip>> stripsMatcher) {
49 return new TypeSafeDiagnosingMatcher<Comic>() {
51 protected boolean matchesSafely(Comic comic, Description mismatchDescription) {
52 if (!Objects.equals(comic.title(), title)) {
53 mismatchDescription.appendText("title is ").appendValue(comic.title());
56 if (!stripsMatcher.matches(comic.strips())) {
57 stripsMatcher.describeMismatch(comic.strips(), mismatchDescription);
64 public void describeTo(Description description) {
65 description.appendText("is comic with title ").appendValue(title);
66 description.appendText(" and strips ").appendValueList("(", ", ", ")", stripsMatcher);
71 private Matcher<? super Strip> isStrip(String url, String comment) {
72 return new TypeSafeDiagnosingMatcher<Strip>() {
74 protected boolean matchesSafely(Strip strip, Description mismatchDescription) {
75 if (!Objects.equals(strip.imageUrl(), url)) {
76 mismatchDescription.appendText("image URL is ").appendValue(strip.imageUrl());
79 if (!Objects.equals(strip.comment(), comment)) {
80 mismatchDescription.appendText("comment is ").appendValue(strip.comment());
87 public void describeTo(Description description) {
88 description.appendText("is strip from ").appendValue(url);
89 description.appendText(" with comment ").appendValue(comment);