1 package net.pterodactylus.rhynodge.filters.comics;
3 import java.util.Objects;
5 import net.pterodactylus.rhynodge.states.ComicState.Comic;
6 import net.pterodactylus.rhynodge.states.ComicState.Strip;
8 import org.hamcrest.Description;
9 import org.hamcrest.Matcher;
10 import org.hamcrest.TypeSafeDiagnosingMatcher;
13 * Matchers for comics.
15 * @author <a href="mailto:david.roden@bietr.de">David Roden</a>
17 public class ComicMatchers {
19 public static Matcher<? super Comic> isComic(String title, Matcher<Iterable<? extends Strip>> stripsMatcher) {
20 return new TypeSafeDiagnosingMatcher<Comic>() {
22 protected boolean matchesSafely(Comic comic, Description mismatchDescription) {
23 if (!Objects.equals(comic.title(), title)) {
24 mismatchDescription.appendText("title is ").appendValue(comic.title());
27 if (!stripsMatcher.matches(comic.strips())) {
28 stripsMatcher.describeMismatch(comic.strips(), mismatchDescription);
35 public void describeTo(Description description) {
36 description.appendText("is comic with title ").appendValue(title);
37 description.appendText(" and strips ").appendValueList("(", ", ", ")", stripsMatcher);
42 public static Matcher<? super Strip> isStrip(String url, String comment) {
43 return new TypeSafeDiagnosingMatcher<Strip>() {
45 protected boolean matchesSafely(Strip strip, Description mismatchDescription) {
46 if (!Objects.equals(strip.imageUrl(), url)) {
47 mismatchDescription.appendText("image URL is ").appendValue(strip.imageUrl());
50 if (!Objects.equals(strip.comment(), comment)) {
51 mismatchDescription.appendText("comment is ").appendValue(strip.comment());
58 public void describeTo(Description description) {
59 description.appendText("is strip from ").appendValue(url);
60 description.appendText(" with comment ").appendValue(comment);