Add unit test for pirate bay filter
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / torrents / PirateBayFilterTest.java
1 package net.pterodactylus.rhynodge.filters.torrents;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.instanceOf;
5
6 import java.io.IOException;
7
8 import net.pterodactylus.rhynodge.filters.ResourceLoader;
9 import net.pterodactylus.rhynodge.states.HtmlState;
10 import net.pterodactylus.rhynodge.states.TorrentState;
11
12 import org.hamcrest.Matchers;
13 import org.jsoup.nodes.Document;
14 import org.junit.Test;
15
16 /**
17  * Unit test for {@link PirateBayFilter}.
18  *
19  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
20  */
21 public class PirateBayFilterTest {
22
23         private final PirateBayFilter filter = new PirateBayFilter();
24         private final Document document;
25         private final HtmlState htmlState;
26
27         public PirateBayFilterTest() throws IOException {
28                 document = ResourceLoader.loadDocument(getClass(), "pirate-bay-results.html", "http://uj3wazyk5u4hnvtk.onion/");
29                 htmlState = new HtmlState("http://uj3wazyk5u4hnvtk.onion/", document);
30         }
31
32         @Test
33         public void filterReturnsTorrentState() {
34                 assertThat(filter.filter(htmlState), instanceOf(TorrentState.class));
35         }
36
37         @Test
38         public void testTorrentStateContainsCorrentTorrents() {
39                 TorrentState newState = (TorrentState) filter.filter(htmlState);
40
41                 assertThat(newState.torrentFiles(), Matchers.contains(
42                                 TorrentMatcher.isTorrent("ubuntu-14.04-desktop-amd64.iso", "964 MiB",
43                                                 "magnet:?xt=urn:btih:18ac50d74c61883b3ab4c40f5dd3e35f157de1a2&dn=ubuntu-14.04-desktop-amd64.iso&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
44                                                 3, 0),
45                                 TorrentMatcher.isTorrent("ubuntu 14 04 3 desktop i386 iso (Server)", "1015 MiB",
46                                                 "magnet:?xt=urn:btih:58ad8b464a0a4114e1890492543b6388d50af04a&dn=ubuntu+14+04+3+desktop+i386+iso+%28Server%29&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
47                                                 1, 0),
48                                 TorrentMatcher.isTorrent("ubuntu-gnome-14.04-beta1-desktop-amd64.iso", "890 MiB",
49                                                 "magnet:?xt=urn:btih:baab5076469a52ea9f0d3eeae8263f154da2fbab&dn=ubuntu-gnome-14.04-beta1-desktop-amd64.iso&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
50                                                 0, 0),
51                                 TorrentMatcher.isTorrent("Ubuntu 14.04.1 Server 64 Bit DE ISO", "572 MiB",
52                                                 "magnet:?xt=urn:btih:236fc296473ae52b2ff0c46a8de5ae04236cc774&dn=Ubuntu+14.04.1+Server+64+Bit+DE+ISO&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
53                                                 0, 0),
54                                 TorrentMatcher.isTorrent("Ubuntu 14.04.1 Server 32 Bit DE ISO", "552 MiB",
55                                                 "magnet:?xt=urn:btih:2c0cef0ca97e31dceae9ddf48fe0d85f1fdb4550&dn=Ubuntu+14.04.1+Server+32+Bit+DE+ISO&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80&tr=udp%3A%2F%2Fopen.demonii.com%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fexodus.desync.com%3A6969",
56                                                 0, 0)
57                 ));
58         }
59
60 }