From: David ‘Bombe’ Roden Date: Thu, 20 Oct 2016 17:37:35 +0000 (+0200) Subject: Verify that posts are sorted correctly X-Git-Tag: 0.9.6^2~5 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=4300ec11b26e9f5fab861ce8c8576df302360c87;p=Sone.git Verify that posts are sorted correctly --- diff --git a/src/test/java/net/pterodactylus/sone/web/BookmarksPageTest.java b/src/test/java/net/pterodactylus/sone/web/BookmarksPageTest.java index 2412414..46b0a18 100644 --- a/src/test/java/net/pterodactylus/sone/web/BookmarksPageTest.java +++ b/src/test/java/net/pterodactylus/sone/web/BookmarksPageTest.java @@ -1,7 +1,7 @@ package net.pterodactylus.sone.web; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -12,6 +12,7 @@ import java.util.Set; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException; +import net.pterodactylus.util.collection.Pagination; import org.junit.Test; @@ -32,14 +33,15 @@ public class BookmarksPageTest extends WebPageTest { @Test @SuppressWarnings("unchecked") public void pageSetsCorrectPostsInTemplateContext() throws RedirectException { - Post post1 = createPost(true); - Post post2 = createPost(true); - Post post3 = createPost(true); + Post post1 = createPost(true, 3000L); + Post post2 = createPost(true, 1000L); + Post post3 = createPost(true, 2000L); Set bookmarkedPosts = createBookmarkedPosts(post1, post2, post3); when(core.getBookmarkedPosts()).thenReturn(bookmarkedPosts); when(core.getPreferences().getPostsPerPage()).thenReturn(5); page.processTemplate(freenetRequest, templateContext); - assertThat((Collection) templateContext.get("posts"), containsInAnyOrder(post1, post2, post3)); + assertThat((Collection) templateContext.get("posts"), contains(post1, post3, post2)); + assertThat(((Pagination) templateContext.get("pagination")).getItems(), contains(post1, post3, post2)); assertThat(((Boolean) templateContext.get("postsNotLoaded")), is(false)); } @@ -54,19 +56,23 @@ public class BookmarksPageTest extends WebPageTest { @Test @SuppressWarnings("unchecked") public void notLoadedPostsAreNotIncludedButAFlagIsSet() throws RedirectException { - Post post1 = createPost(true); - Post post2 = createPost(true); - Post post3 = createPost(false); + Post post1 = createPost(true, 1000L); + Post post2 = createPost(true, 3000L); + Post post3 = createPost(false, 2000L); Set bookmarkedPosts = createBookmarkedPosts(post1, post2, post3); when(core.getBookmarkedPosts()).thenReturn(bookmarkedPosts); when(core.getPreferences().getPostsPerPage()).thenReturn(5); page.processTemplate(freenetRequest, templateContext); - assertThat((Collection) templateContext.get("posts"), containsInAnyOrder(post1, post2)); + assertThat((Collection) templateContext.get("posts"), contains(post2, post1)); + assertThat(((Pagination) templateContext.get("pagination")).getItems(), contains(post2, post1)); assertThat(((Boolean) templateContext.get("postsNotLoaded")), is(true)); } - private Post createPost(boolean postLoaded) { - return when(mock(Post.class).isLoaded()).thenReturn(postLoaded).getMock(); + private Post createPost(boolean postLoaded, long time) { + Post post = mock(Post.class); + when(post.isLoaded()).thenReturn(postLoaded); + when(post.getTime()).thenReturn(time); + return post; } }