1 package net.pterodactylus.sone.web.pages
3 import net.pterodactylus.sone.data.Post
4 import net.pterodactylus.sone.data.PostReply
5 import net.pterodactylus.sone.test.asOptional
6 import net.pterodactylus.sone.test.mock
7 import net.pterodactylus.sone.test.whenever
8 import org.hamcrest.MatcherAssert.assertThat
9 import org.hamcrest.Matchers.containsInAnyOrder
10 import org.hamcrest.Matchers.equalTo
11 import org.junit.Before
13 import java.util.Arrays.asList
16 * Unit test for [NewPage].
18 class NewPageTest: WebPageTest() {
20 private val page = NewPage(template, webInterface)
22 override fun getPage() = page
25 fun setupNumberOfPostsPerPage() {
26 webInterface.core.preferences.postsPerPage = 5
30 fun `page returns correct path`() {
31 assertThat(page.path, equalTo("new.html"))
35 fun `page does not require login`() {
36 assertThat(page.requiresLogin(), equalTo(false))
40 fun `page returns correct title`() {
41 addTranslation("Page.New.Title", "new page title")
42 assertThat(page.getPageTitle(freenetRequest), equalTo("new page title"))
46 fun `posts are not duplicated when they come from both new posts and new replies notifications`() {
47 val extraPost = mock<Post>()
48 val posts = asList(mock<Post>(), mock<Post>())
49 val postReplies = asList(mock<PostReply>(), mock<PostReply>())
50 whenever(postReplies[0].post).thenReturn(posts[0].asOptional())
51 whenever(postReplies[1].post).thenReturn(extraPost.asOptional())
52 whenever(webInterface.getNewPosts(currentSone)).thenReturn(posts)
53 whenever(webInterface.getNewReplies(currentSone)).thenReturn(postReplies)
56 val renderedPosts = templateContext.get<List<Post>>("posts", List::class.java)
57 assertThat(renderedPosts, containsInAnyOrder(posts[0], posts[1], extraPost))