Add test for SMBC
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / BlacklistFilterTest.java
1 /*
2  * rhynodge - BlacklistFilterTest.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.rhynodge.filters;
19
20 import static java.util.Arrays.asList;
21 import static net.pterodactylus.rhynodge.filters.BlacklistFilter.createDefaultBlacklistFilter;
22 import static org.hamcrest.MatcherAssert.assertThat;
23 import static org.hamcrest.Matchers.containsInAnyOrder;
24 import static org.hamcrest.Matchers.is;
25 import static org.hamcrest.Matchers.notNullValue;
26
27 import net.pterodactylus.rhynodge.State;
28 import net.pterodactylus.rhynodge.states.FailedState;
29 import net.pterodactylus.rhynodge.states.TorrentState;
30 import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile;
31
32 import org.junit.Test;
33
34 /**
35  * Unit test for {@link BlacklistFilter}.
36  *
37  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38  */
39 public class BlacklistFilterTest {
40
41         private final BlacklistFilter blacklistFilter = new BlacklistFilter(asList("-Haggebulle", "-FooKaS"));
42         private final TorrentFile notMatchingTorrentFile1 = new TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-3LT0N", "1.1G", "magnet:?xt=a", "http://", 1, 2, 3);
43         private final TorrentFile notMatchingTorrentFile2 = new TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-HELLRAZ0R", "1.1G", "magnet:?xt=b", "http://", 1, 2, 3);
44         private final TorrentFile matchingTorrentFile1 = new TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-Haggebulle", "1.1G", "magnet:?xt=c", "http://", 1, 2, 3);
45         private final TorrentFile matchingTorrentFile2 = new TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-FooKaS", "1.1G", "magnet:?xt=d", "http://", 1, 2, 3);
46
47         @Test
48         public void verifyThatMatchingTorrentsAreRemoved() {
49                 TorrentState torrentState = new TorrentState();
50                 torrentState.addTorrentFile(matchingTorrentFile1);
51                 torrentState.addTorrentFile(notMatchingTorrentFile1);
52                 torrentState.addTorrentFile(matchingTorrentFile2);
53                 torrentState.addTorrentFile(notMatchingTorrentFile2);
54                 TorrentState filteredState = (TorrentState) blacklistFilter.filter(torrentState);
55                 assertThat(filteredState, notNullValue());
56                 assertThat(filteredState.torrentFiles(), containsInAnyOrder(notMatchingTorrentFile1, notMatchingTorrentFile2));
57         }
58
59         @Test
60         public void verifyThatAFailedStateResultsInAFailedState() {
61                 State state = blacklistFilter.filter(new FailedState());
62                 assertThat(state, notNullValue());
63                 assertThat(state.success(), is(false));
64         }
65
66         @Test
67         public void verifyThatABlacklistFilterIsCreated() {
68                 assertThat(createDefaultBlacklistFilter(), notNullValue());
69         }
70
71 }