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;
@Test
public void verifyThatCreatingAPostWorks() throws FcpException {
- Sone sone = mocks.mockLocalSone("Sone");
- mocks.mockLocalSone("OtherSone");
+ Sone sone = mocks.mockSone("Sone").local().create();
+ mocks.mockSone("OtherSone").local().create();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
when(mocks.core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
.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")));
@Test
public void verifyThatCreatingAPostWithoutRecipientWorks() throws FcpException {
- Sone sone = mocks.mockLocalSone("Sone");
+ Sone sone = mocks.mockSone("Sone").local().create();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
when(mocks.core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
.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()));
@Test
public void verifyThatCreatingAPostDirectedToTheSendingSoneCausesAnError() throws FcpException {
- mocks.mockLocalSone("Sone");
+ mocks.mockSone("Sone").local().create();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
when(mocks.core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
.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());
}
@Test(expected = FcpException.class)
public void verifyThatCreatingAPostWithoutTextCausesAnError() throws FcpException {
- mocks.mockLocalSone("Sone");
+ mocks.mockSone("Sone").create();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
when(mocks.core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
@Test(expected = FcpException.class)
public void verifyThatCreatingAPostWithoutSoneCausesAnError() throws FcpException {
- mocks.mockLocalSone("Sone");
+ mocks.mockSone("Sone").local().create();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
when(mocks.core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));