X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FGetPostFeedCommandTest.java;h=46f21f3b9c1942504fa46abb2a0fe0df5ac79432;hb=2d37242d19f2e726cd402b99f935a0eba282f630;hp=e54f3382867d85e0c4c3d841af0bf8a0c5349e9b;hpb=964e03744f8c3d918e5c78fb414772a0d2454584;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java index e54f338..46f21f3 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java @@ -20,12 +20,11 @@ package net.pterodactylus.sone.fcp; import static java.lang.System.currentTimeMillis; import static java.util.Arrays.asList; import static java.util.concurrent.TimeUnit.DAYS; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPost; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPostReply; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyPostsWithReplies; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; + +import java.util.Collections; import net.pterodactylus.sone.data.Mocks; import net.pterodactylus.sone.data.Post; @@ -63,7 +62,7 @@ public class GetPostFeedCommandTest { public void setup() { remoteSone = mocks.mockSone("RSone").create(); friendSone = mocks.mockSone("FSone").create(); - localSone = mocks.mockSone("LSone").local().withFriends(asList(friendSone.getId())).create(); + localSone = mocks.mockSone("LSone").local().withFriends(asList(friendSone.getId(), "NonExistingSone")).create(); localPost = mocks.mockPost(localSone, "LPost").withTime(daysBefore(11)).withText("My post.").create(); friendReplyToLocalPost = mocks.mockPostReply(friendSone, "FReply").inReplyTo(localPost).withTime(daysBefore(9)).withText("No.").create(); remoteReplyToLocalPost = mocks.mockPostReply(remoteSone, "RReply").inReplyTo(localPost).withTime(daysBefore(7)).withText("Yes.").create(); @@ -79,16 +78,8 @@ public class GetPostFeedCommandTest { .put("Sone", "LSone") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); - assertThat(response.getReplyParameters().getInt("Posts.Count"), is(3)); - verifyPost(response.getReplyParameters(), "Posts.0.", localPost); - assertThat(response.getReplyParameters().getInt("Posts.0.Replies.Count"), is(2)); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.0.", friendReplyToLocalPost); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.1.", remoteReplyToLocalPost); - verifyPost(response.getReplyParameters(), "Posts.1.", friendPost); - verifyPost(response.getReplyParameters(), "Posts.2.", remotePost); + verifyAnswer(response, "PostFeed"); + verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost, remotePost)); } @Test @@ -99,12 +90,8 @@ public class GetPostFeedCommandTest { .put("StartPost", "1") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); - assertThat(response.getReplyParameters().getInt("Posts.Count"), is(2)); - verifyPost(response.getReplyParameters(), "Posts.0.", friendPost); - verifyPost(response.getReplyParameters(), "Posts.1.", remotePost); + verifyAnswer(response, "PostFeed"); + verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost, remotePost)); } @Test @@ -115,15 +102,8 @@ public class GetPostFeedCommandTest { .put("MaxPosts", "2") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); - assertThat(response.getReplyParameters().getInt("Posts.Count"), is(2)); - verifyPost(response.getReplyParameters(), "Posts.0.", localPost); - assertThat(response.getReplyParameters().getInt("Posts.0.Replies.Count"), is(2)); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.0.", friendReplyToLocalPost); - verifyPostReply(response.getReplyParameters(), "Posts.0.Replies.1.", remoteReplyToLocalPost); - verifyPost(response.getReplyParameters(), "Posts.1.", friendPost); + verifyAnswer(response, "PostFeed"); + verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost)); } @Test @@ -135,11 +115,8 @@ public class GetPostFeedCommandTest { .put("StartPost", "1") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); - assertThat(response.getReplyParameters().getInt("Posts.Count"), is(1)); - verifyPost(response.getReplyParameters(), "Posts.0.", friendPost); + verifyAnswer(response, "PostFeed"); + verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost)); } @Test @@ -150,10 +127,8 @@ public class GetPostFeedCommandTest { .put("StartPost", "10") .get(); Response response = getPostFeedCommand.execute(getPostFeedFieldSet, null, DIRECT); - assertThat(response, notNullValue()); - assertThat(response.getReplyParameters(), notNullValue()); - assertThat(response.getReplyParameters().get("Message"), is("PostFeed")); - assertThat(response.getReplyParameters().getInt("Posts.Count"), is(0)); + verifyAnswer(response, "PostFeed"); + verifyPostsWithReplies(response.getReplyParameters(), "Posts.", Collections.emptyList()); } @Test(expected = FcpException.class)