From 2d37242d19f2e726cd402b99f935a0eba282f630 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 19 Dec 2013 00:38:04 +0100 Subject: [PATCH] Move verifiers to different package. --- .../java/net/pterodactylus/sone/Verifiers.java | 132 +++++++++++++++++++++ .../sone/fcp/AbstractSoneCommandTest.java | 6 +- .../sone/fcp/CreatePostCommandTest.java | 2 +- .../sone/fcp/CreateReplyCommandTest.java | 2 +- .../sone/fcp/DeletePostCommandTest.java | 2 +- .../sone/fcp/DeleteReplyCommandTest.java | 2 +- .../sone/fcp/GetLocalSonesCommandTest.java | 2 +- .../pterodactylus/sone/fcp/GetPostCommandTest.java | 4 +- .../sone/fcp/GetPostFeedCommandTest.java | 4 +- .../sone/fcp/GetPostsCommandTest.java | 4 +- .../pterodactylus/sone/fcp/GetSoneCommandTest.java | 6 +- .../sone/fcp/GetSonesCommandTest.java | 4 +- .../sone/fcp/LikePostCommandTest.java | 2 +- .../sone/fcp/LikeReplyCommandTest.java | 2 +- .../sone/fcp/LockSoneCommandTest.java | 2 +- .../sone/fcp/UnlockSoneCommandTest.java | 2 +- .../java/net/pterodactylus/sone/fcp/Verifiers.java | 132 --------------------- .../pterodactylus/sone/fcp/VersionCommandTest.java | 2 +- 18 files changed, 156 insertions(+), 156 deletions(-) create mode 100644 src/test/java/net/pterodactylus/sone/Verifiers.java delete mode 100644 src/test/java/net/pterodactylus/sone/fcp/Verifiers.java diff --git a/src/test/java/net/pterodactylus/sone/Verifiers.java b/src/test/java/net/pterodactylus/sone/Verifiers.java new file mode 100644 index 0000000..32a359f --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/Verifiers.java @@ -0,0 +1,132 @@ +/* + * Sone - Verifiers.java - Copyright © 2013 David Roden + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.pterodactylus.sone; + +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.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; + +import org.hamcrest.CoreMatchers; + +/** + * Verifiers used throughout the {@link net.pterodactylus.sone.fcp} package. + * + * @author David ‘Bombe’ Roden + */ +public class Verifiers { + + public static void verifyAnswer(Response response, String messageName) { + assertThat(response, notNullValue()); + assertThat(response.getReplyParameters(), notNullValue()); + assertThat(response.getReplyParameters().get("Message"), is(messageName)); + } + + public 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())); + assertThat(replyParameters.get(format("%sRecipient", prefix)), is(post.getRecipientId().orNull())); + assertThat(replyParameters.getLong(format("%sTime", prefix)), is(post.getTime())); + assertThat(replyParameters.get(format("%sText", prefix)), is(post.getText())); + } + + public 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++; + } + } + + public 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())); + assertThat(replyParameters.getLong(format("%sTime", prefix)), is(postReply.getTime())); + assertThat(replyParameters.get(format("%sText", prefix)), is(postReply.getText())); + } + + public 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)) { + verifyPostReply(postFieldSet, prefix + postReplyIndex + ".", postReply); + postReplyIndex++; + } + } + + public 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++; + } + } + + public static void verifyPostWithReplies(SimpleFieldSet postFieldSet, String prefix, Post post) throws FSParseException { + verifyPost(postFieldSet, prefix, post); + verifyPostReplies(postFieldSet, prefix + "Replies.", post.getReplies()); + } + + public static void verifyFollowedSone(SimpleFieldSet simpleFieldSet, String prefix, Sone sone) throws FSParseException { + verifyNotFollowedSone(simpleFieldSet, prefix, sone); + assertThat(simpleFieldSet.getBoolean(prefix + "Followed"), is(true)); + } + + public 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++; + } + } + + public 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++; + } + } + +} diff --git a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java index d510ab6..59287e1 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/AbstractSoneCommandTest.java @@ -24,9 +24,9 @@ import static java.util.UUID.randomUUID; import static java.util.concurrent.TimeUnit.DAYS; import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeSone; import static net.pterodactylus.sone.fcp.AbstractSoneCommand.encodeString; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPostWithReplies; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPosts; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPostsWithReplies; +import static net.pterodactylus.sone.Verifiers.verifyPostWithReplies; +import static net.pterodactylus.sone.Verifiers.verifyPosts; +import static net.pterodactylus.sone.Verifiers.verifyPostsWithReplies; import static net.pterodactylus.sone.template.SoneAccessor.getNiceName; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; diff --git a/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java index a424079..05aedaa 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java @@ -20,7 +20,7 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Optional.of; import static java.lang.System.currentTimeMillis; import static net.pterodactylus.sone.database.PostBuilder.PostCreated; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; diff --git a/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java index 36f99a8..bef609a 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java @@ -18,7 +18,7 @@ package net.pterodactylus.sone.fcp; import static java.lang.System.currentTimeMillis; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; diff --git a/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java index 1e2ce7c..683864c 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java @@ -17,7 +17,7 @@ package net.pterodactylus.sone.fcp; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java index 7a30808..873d1da 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java @@ -17,7 +17,7 @@ package net.pterodactylus.sone.fcp; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java index 85b1bb7..65497d9 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetLocalSonesCommandTest.java @@ -19,7 +19,7 @@ package net.pterodactylus.sone.fcp; import static java.lang.String.format; import static java.util.Arrays.asList; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetPostCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetPostCommandTest.java index 93f55e6..a6a6fea 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetPostCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetPostCommandTest.java @@ -18,8 +18,8 @@ package net.pterodactylus.sone.fcp; import static java.util.Arrays.asList; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPostWithReplies; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyPostWithReplies; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.mockito.Mockito.when; diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java index e272148..46f21f3 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetPostFeedCommandTest.java @@ -20,8 +20,8 @@ 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.verifyAnswer; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPostsWithReplies; +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 java.util.Collections; diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetPostsCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetPostsCommandTest.java index bb2eafa..d4c02cb 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetPostsCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetPostsCommandTest.java @@ -18,8 +18,8 @@ package net.pterodactylus.sone.fcp; import static java.util.Arrays.asList; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; -import static net.pterodactylus.sone.fcp.Verifiers.verifyPostsWithReplies; +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 java.util.Collections; diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetSoneCommandTest.java index 4b51388..24f6737 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetSoneCommandTest.java @@ -18,9 +18,9 @@ package net.pterodactylus.sone.fcp; import static java.util.Arrays.asList; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; -import static net.pterodactylus.sone.fcp.Verifiers.verifyFollowedSone; -import static net.pterodactylus.sone.fcp.Verifiers.verifyNotFollowedSone; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyFollowedSone; +import static net.pterodactylus.sone.Verifiers.verifyNotFollowedSone; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import java.util.Arrays; diff --git a/src/test/java/net/pterodactylus/sone/fcp/GetSonesCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/GetSonesCommandTest.java index 6650a1a..f7d2469 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/GetSonesCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/GetSonesCommandTest.java @@ -18,8 +18,8 @@ package net.pterodactylus.sone.fcp; import static java.util.Arrays.asList; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; -import static net.pterodactylus.sone.fcp.Verifiers.verifySones; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifySones; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import java.util.Collections; diff --git a/src/test/java/net/pterodactylus/sone/fcp/LikePostCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/LikePostCommandTest.java index dd3f63f..f17a6b7 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/LikePostCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/LikePostCommandTest.java @@ -17,7 +17,7 @@ package net.pterodactylus.sone.fcp; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/net/pterodactylus/sone/fcp/LikeReplyCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/LikeReplyCommandTest.java index 610ed6c..a921953 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/LikeReplyCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/LikeReplyCommandTest.java @@ -17,7 +17,7 @@ package net.pterodactylus.sone.fcp; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; diff --git a/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java index 5ed051e..e4bbeec 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/LockSoneCommandTest.java @@ -18,7 +18,7 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Optional.of; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.eq; diff --git a/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java index d73b6e3..adb6b96 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/UnlockSoneCommandTest.java @@ -18,7 +18,7 @@ package net.pterodactylus.sone.fcp; import static com.google.common.base.Optional.of; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.eq; diff --git a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java b/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java deleted file mode 100644 index ed1a0f3..0000000 --- a/src/test/java/net/pterodactylus/sone/fcp/Verifiers.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Sone - Verifiers.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -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.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; - -import org.hamcrest.CoreMatchers; - -/** - * Verifiers used throughout the {@link net.pterodactylus.sone.fcp} package. - * - * @author David ‘Bombe’ Roden - */ -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())); - assertThat(replyParameters.get(format("%sRecipient", prefix)), is(post.getRecipientId().orNull())); - assertThat(replyParameters.getLong(format("%sTime", prefix)), is(post.getTime())); - 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())); - assertThat(replyParameters.getLong(format("%sTime", prefix)), is(postReply.getTime())); - assertThat(replyParameters.get(format("%sText", prefix)), is(postReply.getText())); - } - - 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)) { - verifyPostReply(postFieldSet, prefix + postReplyIndex + ".", postReply); - postReplyIndex++; - } - } - - 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++; - } - } - -} diff --git a/src/test/java/net/pterodactylus/sone/fcp/VersionCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/VersionCommandTest.java index bdfd31e..123b296 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/VersionCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/VersionCommandTest.java @@ -17,7 +17,7 @@ package net.pterodactylus.sone.fcp; -import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer; +import static net.pterodactylus.sone.Verifiers.verifyAnswer; import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT; import static net.pterodactylus.sone.main.SonePlugin.VERSION; import static org.hamcrest.MatcherAssert.assertThat; -- 2.7.4