X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FVerifiers.java;h=ed1a0f3e693658e04e5823b4cb5c8f492ec53f34;hb=7849b848a3109eff340ec80e406c761bb95b3192;hp=e2822104ae2f98abd850e7f1bff44020494ee8ba;hpb=f479ac8ae786d02c07a14bd0cce5e09776ca9c35;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java index e282210..ed1a0f3 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java +++ b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java @@ -20,13 +20,18 @@ package net.pterodactylus.sone.fcp; import static com.google.common.collect.FluentIterable.from; import static java.lang.String.format; import static net.pterodactylus.sone.data.Reply.FUTURE_REPLY_FILTER; +import static net.pterodactylus.sone.template.SoneAccessor.getNiceName; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; -import java.util.Collection; +import java.util.List; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.PostReply; +import net.pterodactylus.sone.data.Profile.Field; +import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.freenet.fcp.Command.Response; import freenet.node.FSParseException; import freenet.support.SimpleFieldSet; @@ -40,6 +45,12 @@ import org.hamcrest.CoreMatchers; */ public class Verifiers { + static void verifyAnswer(Response response, String messageName) { + assertThat(response, notNullValue()); + assertThat(response.getReplyParameters(), notNullValue()); + assertThat(response.getReplyParameters().get("Message"), is(messageName)); + } + static void verifyPost(SimpleFieldSet replyParameters, String prefix, Post post) throws FSParseException { assertThat(replyParameters.get(format("%sID", prefix)), is(post.getId())); assertThat(replyParameters.get(format("%sSone", prefix)), is(post.getSone().getId())); @@ -48,6 +59,15 @@ public class Verifiers { assertThat(replyParameters.get(format("%sText", prefix)), is(post.getText())); } + static void verifyPosts(SimpleFieldSet postFieldSet, String prefix, List posts) throws FSParseException { + assertThat(postFieldSet.getInt(prefix + "Count"), CoreMatchers.is(posts.size())); + int postIndex = 0; + for (Post post : posts) { + verifyPost(postFieldSet, prefix + postIndex + ".", post); + postIndex++; + } + } + static void verifyPostReply(SimpleFieldSet replyParameters, String prefix, PostReply postReply) throws FSParseException { assertThat(replyParameters.get(format("%sID", prefix)), is(postReply.getId())); assertThat(replyParameters.get(format("%sSone", prefix)), is(postReply.getSone().getId())); @@ -55,7 +75,7 @@ public class Verifiers { assertThat(replyParameters.get(format("%sText", prefix)), is(postReply.getText())); } - static void verifyPostReplies(SimpleFieldSet postFieldSet, String prefix, Collection postReplies) throws FSParseException { + static void verifyPostReplies(SimpleFieldSet postFieldSet, String prefix, List postReplies) throws FSParseException { assertThat(postFieldSet.getInt(prefix + "Count"), CoreMatchers.is(from(postReplies).filter(FUTURE_REPLY_FILTER).size())); int postReplyIndex = 0; for (PostReply postReply : from(postReplies).filter(FUTURE_REPLY_FILTER)) { @@ -64,4 +84,49 @@ public class Verifiers { } } + static void verifyPostsWithReplies(SimpleFieldSet postFieldSet, String prefix, List posts) throws FSParseException { + assertThat(postFieldSet.getInt(prefix + "Count"), CoreMatchers.is(posts.size())); + int postIndex = 0; + for (Post post : posts) { + verifyPost(postFieldSet, prefix + postIndex + ".", post); + verifyPostReplies(postFieldSet, prefix + postIndex + ".Replies.", post.getReplies()); + postIndex++; + } + } + + static void verifyPostWithReplies(SimpleFieldSet postFieldSet, String prefix, Post post) throws FSParseException { + verifyPost(postFieldSet, prefix, post); + verifyPostReplies(postFieldSet, prefix + "Replies.", post.getReplies()); + } + + static void verifyFollowedSone(SimpleFieldSet simpleFieldSet, String prefix, Sone sone) throws FSParseException { + verifyNotFollowedSone(simpleFieldSet, prefix, sone); + assertThat(simpleFieldSet.getBoolean(prefix + "Followed"), is(true)); + } + + static void verifyNotFollowedSone(SimpleFieldSet simpleFieldSet, String prefix, Sone sone) throws FSParseException { + assertThat(simpleFieldSet.get(prefix + "Name"), is(sone.getName())); + assertThat(simpleFieldSet.get(prefix + "NiceName"), is(getNiceName(sone))); + assertThat(simpleFieldSet.getLong(prefix + "LastUpdated"), is(sone.getTime())); + assertThat(simpleFieldSet.getInt(prefix + "Field.Count"), is(sone.getProfile().getFields().size())); + int fieldIndex = 0; + for (Field field : sone.getProfile().getFields()) { + assertThat(simpleFieldSet.get(prefix + "Field." + fieldIndex + ".Name"), is(field.getName())); + assertThat(simpleFieldSet.get(prefix + "Field." + fieldIndex + ".Value"), is(field.getValue())); + fieldIndex++; + } + } + + static void verifySones(SimpleFieldSet simpleFieldSet, String prefix, List sones) throws FSParseException { + assertThat(simpleFieldSet.getInt(prefix + "Count"), is(sones.size())); + int soneIndex = 0; + for (Sone sone : sones) { + assertThat(simpleFieldSet.get(prefix + soneIndex + ".ID"), is(sone.getId())); + assertThat(simpleFieldSet.get(prefix + soneIndex + ".Name"), is(sone.getName())); + assertThat(simpleFieldSet.get(prefix + soneIndex + ".NiceName"), is(getNiceName(sone))); + assertThat(simpleFieldSet.getLong(prefix + soneIndex + ".Time"), is(sone.getTime())); + soneIndex++; + } + } + }