1 package net.pterodactylus.rhynodge.filters.comics;
3 import java.io.IOException;
5 import net.pterodactylus.rhynodge.Filter;
6 import net.pterodactylus.rhynodge.State;
7 import net.pterodactylus.rhynodge.filters.ResourceLoader;
8 import net.pterodactylus.rhynodge.states.ComicState;
9 import net.pterodactylus.rhynodge.states.ComicState.Comic;
10 import net.pterodactylus.rhynodge.states.ComicState.Strip;
11 import net.pterodactylus.rhynodge.states.HtmlState;
13 import org.hamcrest.Description;
14 import org.hamcrest.Matcher;
15 import org.hamcrest.MatcherAssert;
16 import org.hamcrest.Matchers;
17 import org.hamcrest.TypeSafeDiagnosingMatcher;
18 import org.jsoup.nodes.Document;
19 import org.junit.Test;
23 * Unit test for {@link SinfestComicFilter}.
25 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27 public class SinfestComicFilterTest {
29 private final Filter sinfestFilter = new SinfestComicFilter();
30 private final HtmlState htmlState;
32 public SinfestComicFilterTest() throws IOException {
33 Document document = ResourceLoader.loadDocument(SinfestComicFilter.class, "sinfest.html", "https://sinfest.xyz/");
34 htmlState = new HtmlState("https://sinfest.xyz/", document);
38 public void canParseComicsFromHtml() {
39 State state = sinfestFilter.filter(htmlState);
40 MatcherAssert.assertThat(state, Matchers.instanceOf(ComicState.class));
44 public void imageUrlsAreParsedCorrectly() {
45 ComicState comicState = (ComicState) sinfestFilter.filter(htmlState);
46 MatcherAssert.assertThat(comicState.comics(), Matchers.contains(matchesComic("October 24, 2021: Unperson 33", "https://sinfest.xyz/btphp/comics/2021-10-24.jpg", "")));
49 private Matcher<Comic> matchesComic(String title, String url, String comment) {
50 return new TypeSafeDiagnosingMatcher<Comic>() {
52 protected boolean matchesSafely(Comic comic, Description mismatchDescription) {
53 if (!comic.title().equals(title)) {
54 mismatchDescription.appendText("comic is named ").appendValue(comic.title());
57 if (comic.strips().size() != 1) {
58 mismatchDescription.appendText("comic has ").appendValue(comic.strips().size()).appendText(" strips");
61 Strip strip = comic.strips().get(0);
62 if (!strip.imageUrl().equals(url)) {
63 mismatchDescription.appendText("image url is ").appendValue(strip.imageUrl());
66 if (!strip.comment().equals(comment)) {
67 mismatchDescription.appendText("comment is ").appendValue(strip.comment());
74 public void describeTo(Description description) {
75 description.appendText("comic named ").appendValue(title);
76 description.appendText(" at ").appendValue(url);
77 description.appendText(" with comment ").appendValue(comment);