Factor out torrent matchers.
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / torrents / TorrentzEuFilterTest.java
1 package net.pterodactylus.rhynodge.filters.torrents;
2
3 import java.io.IOException;
4
5 import net.pterodactylus.rhynodge.State;
6 import net.pterodactylus.rhynodge.states.HtmlState;
7 import net.pterodactylus.rhynodge.states.TorrentState;
8
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.jsoup.Jsoup;
12 import org.jsoup.nodes.Document;
13 import org.junit.Test;
14
15 /**
16  * Unit test for {@link TorrentzEuFilter}.
17  *
18  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
19  */
20 public class TorrentzEuFilterTest {
21
22         private final TorrentzEuFilter torrentzEuFilter = new TorrentzEuFilter();
23
24         @Test
25         public void filterCanExtractAllTorrents() throws IOException {
26                 Document document = Jsoup.parse(getClass().getResourceAsStream("torrentz-eu-results.html"), "UTF-8", "http://torrentz.eu/searchA?f=Ubuntu+ISO");
27                 HtmlState htmlState = new HtmlState("http://torrentz.eu/searchA?f=Ubuntu+ISO", document);
28                 State newState = torrentzEuFilter.filter(htmlState);
29                 MatcherAssert.assertThat(newState, Matchers.notNullValue());
30                 MatcherAssert.assertThat(newState, Matchers.instanceOf(TorrentState.class));
31                 TorrentState torrentState = (TorrentState) newState;
32                 MatcherAssert.assertThat(torrentState.torrentFiles(), Matchers.hasSize(2));
33                 MatcherAssert.assertThat(torrentState.torrentFiles(), Matchers.contains(
34                                 TorrentMatcher.isTorrent("Ubuntu 14 04 64Bit ISO File", "981 MB", 0, 1),
35                                 TorrentMatcher.isTorrent("Ubuntu 14 04 LTS Desktop 64bit ISO", "964 MB", 75, 5)
36                 ));
37         }
38
39 }