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.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
-import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.when;
.put("Recipient", "OtherSone")
.get();
Response response = createPostCommand.execute(createPostFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
- assertThat(capturingPostCreated.post, notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("PostCreated"));
+ verifyAnswer(response, "PostCreated");
assertThat(response.getReplyParameters().get("Post"), is(capturingPostCreated.post.getId()));
assertThat(capturingPostCreated.post.getSone(), is(sone));
assertThat(capturingPostCreated.post.getRecipientId(), is(of("OtherSone")));
.put("Text", "Text of the post.")
.get();
Response response = createPostCommand.execute(createPostFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
- assertThat(capturingPostCreated.post, notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("PostCreated"));
+ verifyAnswer(response, "PostCreated");
assertThat(response.getReplyParameters().get("Post"), is(capturingPostCreated.post.getId()));
assertThat(capturingPostCreated.post.getSone(), is(sone));
assertThat(capturingPostCreated.post.getRecipientId(), is(Optional.<String>absent()));
.put("Text", "Text of the post.")
.get();
Response response = createPostCommand.execute(createPostFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("Error"));
+ verifyAnswer(response, "Error");
assertThat(capturingPostCreated.post, nullValue());
}
package net.pterodactylus.sone.fcp;
import static java.lang.System.currentTimeMillis;
+import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
.put("Text", "Text of the reply.")
.get();
Response response = createReplyCommand.execute(createReplyFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
+ verifyAnswer(response, "ReplyCreated");
assertThat(capturingPostReplyCreated.postReply, notNullValue());
assertThat(capturingPostReplyCreated.postReply.getId(), notNullValue());
assertThat(capturingPostReplyCreated.postReply.getPostId(), is("PostId"));
assertThat(capturingPostReplyCreated.postReply.getSone(), is(sone));
assertThat(capturingPostReplyCreated.postReply.getTime(), allOf(greaterThanOrEqualTo(now), lessThanOrEqualTo(currentTimeMillis())));
assertThat(capturingPostReplyCreated.postReply.getText(), is("Text of the reply."));
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("ReplyCreated"));
assertThat(response.getReplyParameters().get("Reply"), is(capturingPostReplyCreated.postReply.getId()));
}
package net.pterodactylus.sone.fcp;
+import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer;
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 static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.Mockito.doNothing;
.put("Post", "PostId")
.get();
Response response = deletePostCommand.execute(deletePostFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("PostDeleted"));
+ verifyAnswer(response, "PostDeleted");
assertThat(deletedPost.getValue(), is(post));
}
.put("Post", "PostId")
.get();
Response response = deletePostCommand.execute(deletePostFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("Error"));
+ verifyAnswer(response, "Error");
assertThat(response.getReplyParameters().get("ErrorCode"), is("401"));
}
package net.pterodactylus.sone.fcp;
+import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer;
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 static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.Mockito.doNothing;
.put("Reply", "ReplyId")
.get();
Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
+ verifyAnswer(response, "ReplyDeleted");
assertThat(postReplyCaptor.getValue(), is(postReply));
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("ReplyDeleted"));
}
@Test(expected = FcpException.class)
.put("Reply", "ReplyId")
.get();
Response response = deleteReplyCommand.execute(deleteReplyFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("Error"));
+ verifyAnswer(response, "Error");
assertThat(response.getReplyParameters().get("ErrorCode"), is("401"));
}
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.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.Collection;
import java.util.List;
mocks.mockSone("RSone2").create();
SimpleFieldSet getLocalSonesFieldSet = new SimpleFieldSetBuilder().put("Message", "GetLocalSones").get();
Response response = getLocalSonesCommand.execute(getLocalSonesFieldSet, null, DIRECT);
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("ListLocalSones"));
+ verifyAnswer(response, "ListLocalSones");
Collection<ParsedSone> parsedSones = parseSones(response.getReplyParameters(), "LocalSones.");
assertThat(parsedSones, matchesSones(localSones));
}
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.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;
.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"));
+ verifyAnswer(response, "PostFeed");
verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost, remotePost));
}
.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"));
+ verifyAnswer(response, "PostFeed");
verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost, remotePost));
}
.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"));
+ verifyAnswer(response, "PostFeed");
verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(localPost, friendPost));
}
.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"));
+ verifyAnswer(response, "PostFeed");
verifyPostsWithReplies(response.getReplyParameters(), "Posts.", asList(friendPost));
}
.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"));
+ verifyAnswer(response, "PostFeed");
verifyPostsWithReplies(response.getReplyParameters(), "Posts.", Collections.<Post>emptyList());
}
package net.pterodactylus.sone.fcp;
import static com.google.common.base.Optional.of;
+import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer;
import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
Response response = lockSoneCommand.execute(fields, null, null);
verify(core).lockSone(eq(localSone));
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("SoneLocked"));
+ verifyAnswer(response, "SoneLocked");
assertThat(response.getReplyParameters().get("Sone"), is("LocalSone"));
}
package net.pterodactylus.sone.fcp;
import static com.google.common.base.Optional.of;
+import static net.pterodactylus.sone.fcp.Verifiers.verifyAnswer;
import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
Response response = unlockSoneCommand.execute(fields, null, null);
verify(core).unlockSone(eq(localSone));
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("SoneUnlocked"));
+ verifyAnswer(response, "SoneUnlocked");
assertThat(response.getReplyParameters().get("Sone"), is("LocalSone"));
}