🔀 Merge branch 'release/v82'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / data / ReplyTest.kt
1 /**
2  * Sone - ReplyTest.kt - Copyright Â© 2020 David â€˜Bombe’ 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.sone.data
19
20 import net.pterodactylus.sone.test.emptyPostReply
21 import org.hamcrest.MatcherAssert.assertThat
22 import org.hamcrest.Matchers.equalTo
23 import org.hamcrest.Matchers.greaterThan
24 import org.hamcrest.Matchers.lessThan
25 import java.util.concurrent.TimeUnit.DAYS
26 import kotlin.test.Test
27
28 class ReplyTest {
29
30         @Test
31         fun `newestReplyFirst comparator returns less-than 0 is first reply is newer than second`() {
32                 val newerReply = emptyPostReply(time = 2000)
33                 val olderReply = emptyPostReply(time = 1000)
34                 assertThat(newestReplyFirst.compare(newerReply, olderReply), lessThan(0))
35         }
36
37         @Test
38         fun `newestReplyFirst comparator returns greater-than 0 is first reply is older than second`() {
39                 val newerReply = emptyPostReply(time = 2000)
40                 val olderReply = emptyPostReply(time = 1000)
41                 assertThat(newestReplyFirst.compare(olderReply, newerReply), greaterThan(0))
42         }
43
44         @Test
45         fun `newestReplyFirst comparator returns 0 is first and second reply have same age`() {
46                 val reply1 = emptyPostReply(time = 1000)
47                 val reply2 = emptyPostReply(time = 1000)
48                 assertThat(newestReplyFirst.compare(reply1, reply2), equalTo(0))
49         }
50
51         @Test
52         fun `noFutureReply filter recognizes reply from the future`() {
53                 val futureReply = emptyPostReply(time = System.currentTimeMillis() + DAYS.toMillis(1))
54                 assertThat(noFutureReply(futureReply), equalTo(false))
55         }
56
57         @Test
58         fun `noFutureReply filter recognizes reply from the present`() {
59                 val futureReply = emptyPostReply(time = System.currentTimeMillis())
60                 assertThat(noFutureReply(futureReply), equalTo(true))
61         }
62
63 }