🔀 Merge branch 'website/epic-games' into next
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / comics / ComicMatchers.java
1 package net.pterodactylus.rhynodge.filters.comics;
2
3 import java.util.Objects;
4
5 import net.pterodactylus.rhynodge.states.ComicState.Comic;
6 import net.pterodactylus.rhynodge.states.ComicState.Strip;
7
8 import org.hamcrest.Description;
9 import org.hamcrest.Matcher;
10 import org.hamcrest.TypeSafeDiagnosingMatcher;
11
12 /**
13  * Matchers for comics.
14  *
15  * @author <a href="mailto:david.roden@bietr.de">David Roden</a>
16  */
17 public class ComicMatchers {
18
19         public static Matcher<? super Comic> isComic(String title, Matcher<Iterable<? extends Strip>> stripsMatcher) {
20                 return new TypeSafeDiagnosingMatcher<Comic>() {
21                         @Override
22                         protected boolean matchesSafely(Comic comic, Description mismatchDescription) {
23                                 if (!Objects.equals(comic.title(), title)) {
24                                         mismatchDescription.appendText("title is ").appendValue(comic.title());
25                                         return false;
26                                 }
27                                 if (!stripsMatcher.matches(comic.strips())) {
28                                         stripsMatcher.describeMismatch(comic.strips(), mismatchDescription);
29                                         return false;
30                                 }
31                                 return true;
32                         }
33
34                         @Override
35                         public void describeTo(Description description) {
36                                 description.appendText("is comic with title ").appendValue(title);
37                                 description.appendText(" and strips ").appendValueList("(", ", ", ")", stripsMatcher);
38                         }
39                 };
40         }
41
42         public static Matcher<? super Strip> isStrip(String url, String comment) {
43                 return new TypeSafeDiagnosingMatcher<Strip>() {
44                         @Override
45                         protected boolean matchesSafely(Strip strip, Description mismatchDescription) {
46                                 if (!Objects.equals(strip.imageUrl(), url)) {
47                                         mismatchDescription.appendText("image URL is ").appendValue(strip.imageUrl());
48                                         return false;
49                                 }
50                                 if (!Objects.equals(strip.comment(), comment)) {
51                                         mismatchDescription.appendText("comment is ").appendValue(strip.comment());
52                                         return false;
53                                 }
54                                 return true;
55                         }
56
57                         @Override
58                         public void describeTo(Description description) {
59                                 description.appendText("is strip from ").appendValue(url);
60                                 description.appendText(" with comment ").appendValue(comment);
61                         }
62                 };
63         }
64
65 }