Add blacklist filter for certain sizes
[rhynodge.git] / src / test / kotlin / net / pterodactylus / rhynodge / filters / SizeBlacklistFilterTest.kt
1 package net.pterodactylus.rhynodge.filters
2
3 import net.pterodactylus.rhynodge.states.FailedState
4 import net.pterodactylus.rhynodge.states.TorrentState
5 import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile
6 import org.hamcrest.MatcherAssert
7 import org.hamcrest.MatcherAssert.assertThat
8 import org.hamcrest.Matchers
9 import org.hamcrest.Matchers.equalTo
10 import org.junit.Test
11
12 /**
13  * Unit test for [SizeBlacklistFilter].
14  */
15 class SizeBlacklistFilterTest {
16
17         private val filter = SizeBlacklistFilter(listOf("123 MiB", "234 GiB"))
18         private val notMatchingTorrentFile1 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-3LT0N", "123 GiB", "magnet:?xt=a", "http://", 1, 2, 3)
19         private val notMatchingTorrentFile2 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-HELLRAZ0R", "123 MB", "magnet:?xt=b", "http://", 1, 2, 3)
20         private val matchingTorrentFile1 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-Haggebulle", "123 MiB", "magnet:?xt=c", "http://", 1, 2, 3)
21         private val matchingTorrentFile2 = TorrentFile("The Vampire Diaries S05E05 2013 HDRip 720p-FooKaS", "234 GiB", "magnet:?xt=d", "http://", 1, 2, 3)
22
23         @Test
24         fun `filter removes the correct torrents`() {
25                 val filteredState = filter.filter(TorrentState(listOf(
26                                 notMatchingTorrentFile1,
27                                 notMatchingTorrentFile2,
28                                 matchingTorrentFile1,
29                                 matchingTorrentFile2
30                 ))) as TorrentState
31                 assertThat(filteredState.torrentFiles(), Matchers.containsInAnyOrder(
32                                 notMatchingTorrentFile1,
33                                 notMatchingTorrentFile2
34                 ))
35         }
36
37         @Test
38         fun `filter returns failed state for a failed state`() {
39             assertThat(filter.filter(FailedState()).success(), equalTo(false))
40         }
41
42 }