2 * Sone - ReplyTest.kt - Copyright © 2020 David ‘Bombe’ Roden
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.
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.
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/>.
18 package net.pterodactylus.sone.data
20 import net.pterodactylus.sone.test.createPostReply
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
31 fun `newestReplyFirst comparator returns less-than 0 is first reply is newer than second`() {
32 val newerReply = createPostReply(time = 2000)
33 val olderReply = createPostReply(time = 1000)
34 assertThat(newestReplyFirst.compare(newerReply, olderReply), lessThan(0))
38 fun `newestReplyFirst comparator returns greater-than 0 is first reply is older than second`() {
39 val newerReply = createPostReply(time = 2000)
40 val olderReply = createPostReply(time = 1000)
41 assertThat(newestReplyFirst.compare(olderReply, newerReply), greaterThan(0))
45 fun `newestReplyFirst comparator returns 0 is first and second reply have same age`() {
46 val reply1 = createPostReply(time = 1000)
47 val reply2 = createPostReply(time = 1000)
48 assertThat(newestReplyFirst.compare(reply1, reply2), equalTo(0))
52 fun `noFutureReply filter recognizes reply from the future`() {
53 val futureReply = createPostReply(time = System.currentTimeMillis() + DAYS.toMillis(1))
54 assertThat(noFutureReply(futureReply), equalTo(false))
58 fun `noFutureReply filter recognizes reply from the present`() {
59 val futureReply = createPostReply(time = System.currentTimeMillis())
60 assertThat(noFutureReply(futureReply), equalTo(true))