From ef1c8b1a4c079506f2227abcef4444204a6f020b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 18 Mar 2014 18:15:34 +0100 Subject: [PATCH] Add test for episode filter. --- .../rhynodge/filters/EpisodeFilterTest.java | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/net/pterodactylus/rhynodge/filters/EpisodeFilterTest.java 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 index 0000000..109e053 --- /dev/null +++ b/src/test/java/net/pterodactylus/rhynodge/filters/EpisodeFilterTest.java @@ -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 David ‘Bombe’ Roden + */ +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; + } + +} -- 2.7.4