From: David ‘Bombe’ Roden Date: Wed, 24 May 2017 17:36:16 +0000 (+0200) Subject: Replace new page test with Kotlin version X-Git-Tag: 0.9.7^2~205 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=0c887926116aefa2245701890b6d40ec4ca4c838;p=Sone.git Replace new page test with Kotlin version --- diff --git a/src/test/java/net/pterodactylus/sone/web/pages/NewPageTest.java b/src/test/java/net/pterodactylus/sone/web/pages/NewPageTest.java deleted file mode 100644 index 2811e8b..0000000 --- a/src/test/java/net/pterodactylus/sone/web/pages/NewPageTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package net.pterodactylus.sone.web.pages; - -import static java.util.Arrays.asList; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.PostReply; - -import com.google.common.base.Optional; -import org.junit.Before; -import org.junit.Test; - -/** - * Unit test for {@link NewPage}. - * - * @author David ‘Bombe’ Roden - */ -public class NewPageTest extends WebPageTest { - - private final NewPage newPage = new NewPage(template, webInterface); - - @Before - public void setupNumberOfPostsPerPage() { - webInterface.getCore().getPreferences().setPostsPerPage(5); - } - - @Test - public void postsAreNotDuplicatedWhenTheyComeFromBothNewPostsAndNewRepliesNotifications() throws Exception { - // given - Post extraPost = mock(Post.class); - List posts = asList(mock(Post.class), mock(Post.class)); - List postReplies = asList(mock(PostReply.class), mock(PostReply.class)); - when(postReplies.get(0).getPost()).thenReturn(Optional.of(posts.get(0))); - when(postReplies.get(1).getPost()).thenReturn(Optional.of(extraPost)); - when(webInterface.getNewPosts(currentSone)).thenReturn(posts); - when(webInterface.getNewReplies(currentSone)).thenReturn(postReplies); - - // when - newPage.processTemplate(freenetRequest, templateContext); - - // then - List renderedPosts = templateContext.get("posts", List.class); - assertThat(renderedPosts, containsInAnyOrder(posts.get(0), posts.get(1), extraPost)); - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt new file mode 100644 index 0000000..72d87f8 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt @@ -0,0 +1,44 @@ +package net.pterodactylus.sone.web.pages + +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.PostReply +import net.pterodactylus.sone.test.asOptional +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.containsInAnyOrder +import org.junit.Before +import org.junit.Test +import java.util.Arrays.asList + +/** + * Unit test for [NewPage]. + */ +class NewPageTest: WebPageTest() { + + private val page = NewPage(template, webInterface) + + override fun getPage() = page + + @Before + fun setupNumberOfPostsPerPage() { + webInterface.core.preferences.postsPerPage = 5 + } + + @Test + fun `posts are not duplicated when they come from both new posts and new replies notifications`() { + val extraPost = mock() + val posts = asList(mock(), mock()) + val postReplies = asList(mock(), mock()) + whenever(postReplies[0].post).thenReturn(posts[0].asOptional()) + whenever(postReplies[1].post).thenReturn(extraPost.asOptional()) + whenever(webInterface.getNewPosts(currentSone)).thenReturn(posts) + whenever(webInterface.getNewReplies(currentSone)).thenReturn(postReplies) + + verifyNoRedirect { + val renderedPosts = templateContext.get>("posts", List::class.java) + assertThat(renderedPosts, containsInAnyOrder(posts[0], posts[1], extraPost)) + } + } + +}