--- /dev/null
+package net.pterodactylus.rhynodge.filters.comics;
+
+import java.util.Objects;
+
+import net.pterodactylus.rhynodge.states.ComicState.Comic;
+import net.pterodactylus.rhynodge.states.ComicState.Strip;
+
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
+
+/**
+ * Matchers for comics.
+ *
+ * @author <a href="mailto:david.roden@bietr.de">David Roden</a>
+ */
+public class ComicMatchers {
+
+ public static Matcher<? super Comic> isComic(String title, Matcher<Iterable<? extends Strip>> stripsMatcher) {
+ return new TypeSafeDiagnosingMatcher<Comic>() {
+ @Override
+ protected boolean matchesSafely(Comic comic, Description mismatchDescription) {
+ if (!Objects.equals(comic.title(), title)) {
+ mismatchDescription.appendText("title is ").appendValue(comic.title());
+ return false;
+ }
+ if (!stripsMatcher.matches(comic.strips())) {
+ stripsMatcher.describeMismatch(comic.strips(), mismatchDescription);
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("is comic with title ").appendValue(title);
+ description.appendText(" and strips ").appendValueList("(", ", ", ")", stripsMatcher);
+ }
+ };
+ }
+
+ public static Matcher<? super Strip> isStrip(String url, String comment) {
+ return new TypeSafeDiagnosingMatcher<Strip>() {
+ @Override
+ protected boolean matchesSafely(Strip strip, Description mismatchDescription) {
+ if (!Objects.equals(strip.imageUrl(), url)) {
+ mismatchDescription.appendText("image URL is ").appendValue(strip.imageUrl());
+ return false;
+ }
+ if (!Objects.equals(strip.comment(), comment)) {
+ mismatchDescription.appendText("comment is ").appendValue(strip.comment());
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("is strip from ").appendValue(url);
+ description.appendText(" with comment ").appendValue(comment);
+ }
+ };
+ }
+
+}
package net.pterodactylus.rhynodge.filters.comics;
-import static com.google.common.base.Optional.absent;
-import static java.util.Arrays.asList;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-import static org.jsoup.Jsoup.parse;
+import static org.hamcrest.Matchers.contains;
import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
+
+import net.pterodactylus.rhynodge.filters.ComicSiteFilterTest;
+import net.pterodactylus.rhynodge.filters.ResourceLoader;
+import net.pterodactylus.rhynodge.states.ComicState;
+import net.pterodactylus.rhynodge.states.HtmlState;
import org.jsoup.nodes.Document;
import org.junit.Test;
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class HeldentageFilterTest {
+public class HeldentageFilterTest extends ComicSiteFilterTest {
private final HeldentageFilter heldentageFilter = new HeldentageFilter();
- private final Document document;
+ private final HtmlState htmlState;
public HeldentageFilterTest() throws IOException {
- document = loadDocument("heldentage.html", "http://www.der-flix.de/");
- }
-
- private Document loadDocument(String resourceName, String baseUri) throws IOException {
- InputStream inputStream = getClass().getResourceAsStream(resourceName);
- Document document = parse(inputStream, "UTF-8", baseUri);
- return document;
- }
-
- @Test
- public void comicDoesNotHaveATitle() {
- assertThat(heldentageFilter.extractTitle(document), is(absent()));
- }
-
- @Test
- public void comicUrlCanBeFound() {
- assertThat(heldentageFilter.extractImageUrls(document), is(asList("/images/heldentage/Tag_916.jpg")));
+ Document document = ResourceLoader.loadDocument(HeldentageFilter.class, "heldentage.html", "http://www.der-flix.de/");
+ htmlState = new HtmlState("http://www.der-flix.de/", document);
}
@Test
- public void comicDoesNotHaveImageComments() {
- assertThat(heldentageFilter.extractImageComments(document), is(Collections.<String>emptyList()));
+ public void comicIsParsedCorrectly() {
+ ComicState comicState = (ComicState) heldentageFilter.filter(htmlState);
+ assertThat(comicState.comics(), contains(
+ ComicMatchers.isComic("", contains(
+ ComicMatchers.isStrip("http://www.der-flix.de/images/heldentage/Tag_916.jpg", "")
+ ))
+ ));
}
}