1 package net.pterodactylus.sone.web;
3 import static java.util.Arrays.asList;
4 import static org.hamcrest.MatcherAssert.assertThat;
5 import static org.hamcrest.Matchers.containsInAnyOrder;
6 import static org.mockito.Mockito.mock;
7 import static org.mockito.Mockito.when;
11 import net.pterodactylus.sone.data.Post;
12 import net.pterodactylus.sone.data.PostReply;
14 import com.google.common.base.Optional;
15 import org.junit.Before;
16 import org.junit.Test;
19 * Unit test for {@link NewPage}.
21 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
23 public class NewPageTest extends WebPageTest {
25 private final NewPage newPage = new NewPage(template, webInterface);
28 public void setupNumberOfPostsPerPage() {
29 when(webInterface.getCore().getPreferences().getPostsPerPage()).thenReturn(5);
33 public void postsAreNotDuplicatedWhenTheyComeFromBothNewPostsAndNewRepliesNotifications() throws Exception {
35 Post extraPost = mock(Post.class);
36 List<Post> posts = asList(mock(Post.class), mock(Post.class));
37 List<PostReply> postReplies = asList(mock(PostReply.class), mock(PostReply.class));
38 when(postReplies.get(0).getPost()).thenReturn(Optional.of(posts.get(0)));
39 when(postReplies.get(1).getPost()).thenReturn(Optional.of(extraPost));
40 when(webInterface.getNewPosts(currentSone)).thenReturn(posts);
41 when(webInterface.getNewReplies(currentSone)).thenReturn(postReplies);
44 newPage.processTemplate(freenetRequest, templateContext);
47 List<Post> renderedPosts = templateContext.get("posts", List.class);
48 assertThat(renderedPosts, containsInAnyOrder(posts.get(0), posts.get(1), extraPost));