1 package net.pterodactylus.rhynodge.filters.torrents;
3 import java.util.Objects;
5 import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile;
7 import org.hamcrest.Description;
8 import org.hamcrest.Matcher;
9 import org.hamcrest.Matchers;
10 import org.hamcrest.TypeSafeDiagnosingMatcher;
13 * {@link Matcher}s for {@link TorrentFile}s.
15 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
17 public class TorrentMatcher {
19 public static Matcher<TorrentFile> isTorrent(String name, String size, int seedCount, int leechCount) {
20 return new TypeSafeDiagnosingMatcher<TorrentFile>() {
22 protected boolean matchesSafely(TorrentFile torrentFile, Description mismatchDescription) {
23 if (!torrentFile.name().equals(name)) {
24 mismatchDescription.appendText("name is ").appendValue(torrentFile.name());
27 if (!torrentFile.size().equals(size)) {
28 mismatchDescription.appendText("size is ").appendValue(torrentFile.size());
31 if (torrentFile.seedCount() != seedCount) {
32 mismatchDescription.appendText("seed count is ").appendValue(torrentFile.seedCount());
35 if (torrentFile.leechCount() != leechCount) {
36 mismatchDescription.appendText("leech count is ").appendValue(torrentFile.leechCount());
43 public void describeTo(Description description) {
44 description.appendText("torrent named ").appendValue(name);
45 description.appendText(", size ").appendValue(size);
46 description.appendText(", seeds ").appendValue(seedCount);
47 description.appendText(", leechs ").appendValue(leechCount);
52 public static Matcher<TorrentFile> isTorrent(String name, String size, String magnetLink, int seedCount, int leechCount) {
53 return Matchers.allOf(isTorrent(name, size, seedCount, leechCount), torrentWithMagnetLink(magnetLink));
56 private static Matcher<? super TorrentFile> torrentWithMagnetLink(String magnetLink) {
57 return new TypeSafeDiagnosingMatcher<TorrentFile>() {
59 protected boolean matchesSafely(TorrentFile item, Description mismatchDescription) {
60 if (!Objects.equals(item.magnetUri(), magnetLink)) {
61 mismatchDescription.appendText("magnet URI is ").appendValue(item.magnetUri());
68 public void describeTo(Description description) {
69 description.appendText("magnet URI is ").appendValue(magnetLink);