1 package net.pterodactylus.rhynodge.filters;
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.is;
6 import net.pterodactylus.rhynodge.State;
7 import net.pterodactylus.rhynodge.states.EpisodeState;
8 import net.pterodactylus.rhynodge.states.FailedState;
9 import net.pterodactylus.rhynodge.states.HtmlState;
10 import net.pterodactylus.rhynodge.states.TorrentState;
11 import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile;
13 import org.junit.Test;
16 * Unit test for {@link EpisodeFilter}.
18 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
20 public class EpisodeFilterTest {
22 private final EpisodeFilter episodeFilter = new EpisodeFilter();
25 public void processingAFailedStateReturnsAFailedState() {
26 State state = new FailedState();
27 State newState = episodeFilter.filter(state);
28 assertThat(newState.success(), is(false));
31 @Test(expected = IllegalStateException.class)
32 public void episodeFilterRequiresATorrentState() {
33 State state = new HtmlState("http://foo/", null);
34 episodeFilter.filter(state);
38 public void episodeFilterRecognizesEpisodesCorrectly() {
39 State torrentState = createTorrentState();
40 State newState = episodeFilter.filter(torrentState);
41 assertThat(newState instanceof EpisodeState, is(true));
44 private TorrentState createTorrentState() {
45 TorrentState torrentState = new TorrentState();
46 torrentState.addTorrentFile(new TorrentFile("NonEpisodeFile.avi", "123", "magnet:?1", "url1", 1, 2, 3));
47 torrentState.addTorrentFile(new TorrentFile("Some.S01E01.Episode.avi", "234", "magnet:?2", "url2", 2, 3, 4));
48 torrentState.addTorrentFile(new TorrentFile("More.S01E02.Episodes.avi", "345", "magnet:?3", "url3", 3, 4, 5));
49 torrentState.addTorrentFile(new TorrentFile("Some.1x01.Episode.avi", "456", "magnet:?4", "url4", 4, 5, 6));
50 torrentState.addTorrentFile(new TorrentFile("Broken.S01.Episodes.avi", "567", "magnet:?5", "url5", 5, 6, 7));