♻️ Convert MovieExtractorTest to Kotlin
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / EpisodeFilterTest.java
1 package net.pterodactylus.rhynodge.filters;
2
3 import static org.hamcrest.MatcherAssert.assertThat;
4 import static org.hamcrest.Matchers.is;
5
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;
12
13 import org.junit.Test;
14
15 /**
16  * Unit test for {@link EpisodeFilter}.
17  *
18  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
19  */
20 public class EpisodeFilterTest {
21
22         private final EpisodeFilter episodeFilter = new EpisodeFilter();
23
24         @Test
25         public void processingAFailedStateReturnsAFailedState() {
26                 State state = new FailedState();
27                 State newState = episodeFilter.filter(state);
28                 assertThat(newState.success(), is(false));
29         }
30
31         @Test(expected = IllegalStateException.class)
32         public void episodeFilterRequiresATorrentState() {
33                 State state = new HtmlState("http://foo/", null);
34                 episodeFilter.filter(state);
35         }
36
37         @Test
38         public void episodeFilterRecognizesEpisodesCorrectly() {
39                 State torrentState = createTorrentState();
40                 State newState = episodeFilter.filter(torrentState);
41                 assertThat(newState instanceof EpisodeState, is(true));
42         }
43
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));
51                 return torrentState;
52         }
53
54 }