import static com.google.common.base.Optional.of;
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 static org.mockito.Mockito.when;
import net.pterodactylus.sone.data.Mocks;
@Test
public void verifyThatGettingAPostWithoutRepliesAndRecipientWorks() throws FcpException, FSParseException {
- Sone sone = mocks.mockRemoteSone("SoneId");
+ Sone sone = mocks.mockSone("SoneId").create();
Post post = preparePostWithoutRecipient(sone);
SimpleFieldSet getPostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "GetPost")
.put("Post", "PostId")
.get();
Response response = getPostCommand.execute(getPostFieldSet, null, DIRECT);
- verifyAnswer(response);
+ verifyAnswer(response, "Post");
verifyPost(post, response);
}
@Test
public void verifyThatGettingAPostWithoutRepliesAndWithRecipientWorks() throws FcpException, FSParseException {
- Sone sone = mocks.mockRemoteSone("SoneId");
- Sone otherSone = mocks.mockRemoteSone("OtherSoneId");
+ Sone sone = mocks.mockSone("SoneId").create();
+ Sone otherSone = mocks.mockSone("OtherSoneId").create();
Post post = preparePostWithRecipient(sone, otherSone);
SimpleFieldSet getPostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "GetPost")
.put("Post", "PostId")
.get();
Response response = getPostCommand.execute(getPostFieldSet, null, DIRECT);
- verifyAnswer(response);
+ verifyAnswer(response, "Post");
verifyPost(post, response);
}
@Test
public void verifyThatGettingAPostWithRepliesWorks() throws FcpException, FSParseException {
- Sone sone = mocks.mockRemoteSone("SoneId");
+ Sone sone = mocks.mockSone("SoneId").create();
Post post = preparePostWithoutRecipient(sone);
- PostReply postReply1 = mocks.mockPostReply(sone, "Reply1");
+ PostReply postReply1 = mocks.mockPostReply(sone, "Reply1").create();
when(postReply1.getText()).thenReturn("Reply 1.");
- PostReply postReply2 = mocks.mockPostReply(sone, "Reply2");
+ PostReply postReply2 = mocks.mockPostReply(sone, "Reply2").create();
when(postReply2.getText()).thenReturn("Reply 2.");
when(post.getReplies()).thenReturn(asList(postReply1, postReply2));
SimpleFieldSet getPostFieldSet = new SimpleFieldSetBuilder()
.put("IncludeReplies", "true")
.get();
Response response = getPostCommand.execute(getPostFieldSet, null, DIRECT);
- verifyAnswer(response);
+ verifyAnswer(response, "Post");
verifyPost(post, response);
assertThat(response.getReplyParameters().getInt("Post.Replies.Count"), is(post.getReplies().size()));
verifyReply(response.getReplyParameters(), "Post.Replies.0.", postReply1);
}
private Post preparePost(Sone sone) {
- Post post = mocks.mockPost(sone, "PostId");
+ Post post = mocks.mockPost(sone, "PostId").create();
when(post.getText()).thenReturn("Text of the post.");
when(post.getTime()).thenReturn(1000L);
return post;
}
- private void verifyAnswer(Response response) {
- assertThat(response, notNullValue());
- assertThat(response.getReplyParameters(), notNullValue());
- assertThat(response.getReplyParameters().get("Message"), is("Post"));
- }
-
private void verifyReply(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()));