🎨 Add container for new posts/replies
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / NewElementsTest.kt
1 /**
2  * Sone - NewElementsTest.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 package net.pterodactylus.sone.web
18
19 import com.google.inject.Guice
20 import com.google.inject.name.Names.named
21 import net.pterodactylus.sone.data.Post
22 import net.pterodactylus.sone.data.PostReply
23 import net.pterodactylus.sone.notify.ListNotification
24 import net.pterodactylus.sone.notify.matchThisPost
25 import net.pterodactylus.sone.notify.matchThisReply
26 import net.pterodactylus.sone.notify.showAllPosts
27 import net.pterodactylus.sone.notify.showAllReplies
28 import net.pterodactylus.sone.test.createPost
29 import net.pterodactylus.sone.test.createPostReply
30 import net.pterodactylus.sone.test.getInstance
31 import net.pterodactylus.sone.test.isProvidedBy
32 import net.pterodactylus.sone.test.key
33 import net.pterodactylus.util.template.Template
34 import org.hamcrest.MatcherAssert.assertThat
35 import org.hamcrest.Matchers.contains
36 import org.hamcrest.Matchers.containsInAnyOrder
37 import org.junit.Test
38
39 class NewElementsTest {
40
41         private val newPostNotification = ListNotification<Post>("", "", Template())
42         private val newReplyNotification = ListNotification<PostReply>("", "", Template())
43         private val localPostNotification = ListNotification<Post>("", "", Template())
44         private val localReplyNotification = ListNotification<PostReply>("", "", Template())
45         private val newElements = NewElements(newPostNotification, newReplyNotification, localPostNotification, localReplyNotification, showAllPosts, showAllReplies)
46
47         init {
48                 localPostNotification.add(post1)
49                 newPostNotification.add(post2)
50                 localReplyNotification.add(reply1)
51                 newReplyNotification.add(reply2)
52         }
53
54         @Test
55         fun `new elements container can be created by guice`() {
56                 val injector = Guice.createInjector(
57                                 key<ListNotification<Post>>(named("newRemotePost")).isProvidedBy(newPostNotification),
58                                 key<ListNotification<Post>>(named("localPost")).isProvidedBy(localPostNotification),
59                                 key<ListNotification<PostReply>>(named("newRemotePostReply")).isProvidedBy(newReplyNotification),
60                                 key<ListNotification<PostReply>>(named("localReply")).isProvidedBy(localReplyNotification)
61                 )
62                 injector.getInstance<NewElements>()
63         }
64
65         @Test
66         fun `new posts include new and local posts`() {
67                 assertThat(newElements.newPosts, containsInAnyOrder(post1, post2))
68         }
69
70         @Test
71         fun `new posts are filtered`() {
72                 val newElements = NewElements(newPostNotification, newReplyNotification, localPostNotification, localReplyNotification, matchThisPost(post2), showAllReplies)
73                 assertThat(newElements.newPosts, contains(post2))
74         }
75
76         @Test
77         fun `new replies include new and local replies`() {
78                 assertThat(newElements.newReplies, containsInAnyOrder(reply1, reply2))
79         }
80
81         @Test
82         fun `new replies are filtered`() {
83                 val newElements = NewElements(newPostNotification, newReplyNotification, localPostNotification, localReplyNotification, showAllPosts, matchThisReply(reply2))
84                 assertThat(newElements.newReplies, containsInAnyOrder(reply2))
85         }
86
87 }
88
89 private val post1 = createPost()
90 private val post2 = createPost()
91 private val reply1 = createPostReply()
92 private val reply2 = createPostReply()