Add test for episode filter.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 18 Mar 2014 17:15:34 +0000 (18:15 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 18 Mar 2014 17:15:34 +0000 (18:15 +0100)
src/test/java/net/pterodactylus/rhynodge/filters/EpisodeFilterTest.java [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/rhynodge/filters/EpisodeFilterTest.java b/src/test/java/net/pterodactylus/rhynodge/filters/EpisodeFilterTest.java
new file mode 100644 (file)
index 0000000..109e053
--- /dev/null
@@ -0,0 +1,54 @@
+package net.pterodactylus.rhynodge.filters;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+
+import net.pterodactylus.rhynodge.State;
+import net.pterodactylus.rhynodge.states.EpisodeState;
+import net.pterodactylus.rhynodge.states.FailedState;
+import net.pterodactylus.rhynodge.states.HtmlState;
+import net.pterodactylus.rhynodge.states.TorrentState;
+import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link EpisodeFilter}.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class EpisodeFilterTest {
+
+       private final EpisodeFilter episodeFilter = new EpisodeFilter();
+
+       @Test
+       public void processingAFailedStateReturnsAFailedState() {
+               State state = new FailedState();
+               State newState = episodeFilter.filter(state);
+               assertThat(newState.success(), is(false));
+       }
+
+       @Test(expected = IllegalStateException.class)
+       public void episodeFilterRequiresATorrentState() {
+               State state = new HtmlState("http://foo/", null);
+               episodeFilter.filter(state);
+       }
+
+       @Test
+       public void episodeFilterRecognizesEpisodesCorrectly() {
+               State torrentState = createTorrentState();
+               State newState = episodeFilter.filter(torrentState);
+               assertThat(newState instanceof EpisodeState, is(true));
+       }
+
+       private TorrentState createTorrentState() {
+               TorrentState torrentState = new TorrentState();
+               torrentState.addTorrentFile(new TorrentFile("NonEpisodeFile.avi", "123", "magnet:?1", "url1", 1, 2, 3));
+               torrentState.addTorrentFile(new TorrentFile("Some.S01E01.Episode.avi", "234", "magnet:?2", "url2", 2, 3, 4));
+               torrentState.addTorrentFile(new TorrentFile("More.S01E02.Episodes.avi", "345", "magnet:?3", "url3", 3, 4, 5));
+               torrentState.addTorrentFile(new TorrentFile("Some.1x01.Episode.avi", "456", "magnet:?4", "url4", 4, 5, 6));
+               torrentState.addTorrentFile(new TorrentFile("Broken.S01.Episodes.avi", "567", "magnet:?5", "url5", 5, 6, 7));
+               return torrentState;
+       }
+
+}