From 8706e3759da1a901c8305003f910b1a6beb7dc88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 30 Mar 2016 13:47:57 +0200 Subject: [PATCH] Add unit test for pirate bay filter --- .../rhynodge/filters/torrents/PirateBayFilter.java | 2 +- .../filters/torrents/pirate-bay-results.html | 290 +++++++++++++++++++++ .../filters/torrents/PirateBayFilterTest.java | 60 +++++ 3 files changed, 351 insertions(+), 1 deletion(-) create mode 100644 src/main/java/net/pterodactylus/rhynodge/filters/torrents/pirate-bay-results.html create mode 100644 src/test/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilterTest.java diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java index 06b1a9c..a71590b 100644 --- a/src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java +++ b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilter.java @@ -54,7 +54,7 @@ public class PirateBayFilter extends TorrentSiteFilter { */ @Override protected String extractSize(Element dataRow) { - return dataRow.select(".detDesc").text().split(Pattern.quote(","))[1].split(Pattern.quote("Size"))[1]; + return dataRow.select(".detDesc").text().split(Pattern.quote(","))[1].split(Pattern.quote("Size"))[1].trim().replace('\u00a0', ' '); } /** diff --git a/src/main/java/net/pterodactylus/rhynodge/filters/torrents/pirate-bay-results.html b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/pirate-bay-results.html new file mode 100644 index 0000000..c690446 --- /dev/null +++ b/src/main/java/net/pterodactylus/rhynodge/filters/torrents/pirate-bay-results.html @@ -0,0 +1,290 @@ + + + + + The Pirate Bay - The galaxy's most resilient bittorrent site + + + + + + + + + + + + + + + + + + + + + +

Search results: Ubuntu 14 04 ISO Displaying hits from 0 to 5 (approx 5 found)

+ +
+
+ +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Type
Name (Order by: Uploaded, Size, ULed by, SE, LE)
View: Single / Double 
SELE
+
+ Applications
+ (UNIX) +
+
+ + Magnet link + Uploaded 04-17 2014, Size 964 MiB, ULed by dchani + 30
+
+ Applications
+ (UNIX) +
+
+ + Magnet link + Uploaded 12-03 2015, Size 1015 MiB, ULed by aquilaxxd + 10
+
+ Applications
+ (UNIX) +
+
+ + Magnet link + Uploaded 04-14 2014, Size 890 MiB, ULed by Anonymous + 00
+
+ Applications
+ (UNIX) +
+
+ + Magnet link + Uploaded 06-28 2015, Size 572 MiB, ULed by zgraggen + 00
+
+ Applications
+ (UNIX) +
+
+ + Magnet link + Uploaded 06-28 2015, Size 552 MiB, ULed by zgraggen + 00
+
+
+
+ +
+ +
+ + + + + + diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilterTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilterTest.java new file mode 100644 index 0000000..11f7019 --- /dev/null +++ b/src/test/java/net/pterodactylus/rhynodge/filters/torrents/PirateBayFilterTest.java @@ -0,0 +1,60 @@ +package net.pterodactylus.rhynodge.filters.torrents; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; + +import java.io.IOException; + +import net.pterodactylus.rhynodge.filters.ResourceLoader; +import net.pterodactylus.rhynodge.states.HtmlState; +import net.pterodactylus.rhynodge.states.TorrentState; + +import org.hamcrest.Matchers; +import org.jsoup.nodes.Document; +import org.junit.Test; + +/** + * Unit test for {@link PirateBayFilter}. + * + * @author David ‘Bombe’ Roden + */ +public class PirateBayFilterTest { + + private final PirateBayFilter filter = new PirateBayFilter(); + private final Document document; + private final HtmlState htmlState; + + public PirateBayFilterTest() throws IOException { + document = ResourceLoader.loadDocument(getClass(), "pirate-bay-results.html", "http://uj3wazyk5u4hnvtk.onion/"); + htmlState = new HtmlState("http://uj3wazyk5u4hnvtk.onion/", document); + } + + @Test + public void filterReturnsTorrentState() { + assertThat(filter.filter(htmlState), instanceOf(TorrentState.class)); + } + + @Test + public void testTorrentStateContainsCorrentTorrents() { + TorrentState newState = (TorrentState) filter.filter(htmlState); + + assertThat(newState.torrentFiles(), Matchers.contains( + TorrentMatcher.isTorrent("ubuntu-14.04-desktop-amd64.iso", "964 MiB", + "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", + 3, 0), + TorrentMatcher.isTorrent("ubuntu 14 04 3 desktop i386 iso (Server)", "1015 MiB", + "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", + 1, 0), + TorrentMatcher.isTorrent("ubuntu-gnome-14.04-beta1-desktop-amd64.iso", "890 MiB", + "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", + 0, 0), + TorrentMatcher.isTorrent("Ubuntu 14.04.1 Server 64 Bit DE ISO", "572 MiB", + "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", + 0, 0), + TorrentMatcher.isTorrent("Ubuntu 14.04.1 Server 32 Bit DE ISO", "552 MiB", + "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", + 0, 0) + )); + } + +} -- 2.7.4