Move verifiers to different package.
[Sone.git] / src / test / java / net / pterodactylus / sone / fcp / CreateReplyCommandTest.java
index 6317c8f..bef609a 100644 (file)
 package net.pterodactylus.sone.fcp;
 
 import static java.lang.System.currentTimeMillis;
-import static net.pterodactylus.sone.data.Mocks.mockCore;
-import static net.pterodactylus.sone.data.Mocks.mockDatabase;
-import static net.pterodactylus.sone.data.Mocks.mockLocalSone;
-import static net.pterodactylus.sone.data.Mocks.mockPost;
+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;
@@ -31,10 +28,9 @@ import static org.hamcrest.Matchers.notNullValue;
 import static org.hamcrest.core.AllOf.allOf;
 import static org.mockito.Mockito.when;
 
-import net.pterodactylus.sone.core.Core;
+import net.pterodactylus.sone.data.Mocks;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.PostReplyBuilder.PostReplyCreated;
 import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
 import net.pterodactylus.sone.freenet.fcp.Command.Response;
@@ -53,16 +49,15 @@ import org.junit.Test;
 public class CreateReplyCommandTest {
 
        private final long now = currentTimeMillis();
-       private final Database database = mockDatabase();
-       private final Core core = mockCore(database);
-       private final CreateReplyCommand createReplyCommand = new CreateReplyCommand(core);
+       private final Mocks mocks = new Mocks();
+       private final CreateReplyCommand createReplyCommand = new CreateReplyCommand(mocks.core);
 
        @Test
        public void verifyThatCreatingAFullySpecifiedReplyWorks() throws FcpException {
-               Sone sone = mockLocalSone(core, "SoneId");
-               mockPost(core, sone, "PostId");
+               Sone sone = mocks.mockSone("SoneId").local().create();
+               mocks.mockPost(sone, "PostId").create();
                CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
-               when(core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
+               when(mocks.core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
                SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
                                .put("Message", "CreateReply")
                                .put("Sone", "SoneId")
@@ -70,24 +65,22 @@ public class CreateReplyCommandTest {
                                .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()));
        }
 
        @Test(expected = FcpException.class)
        public void verifyThatCreatingAReplyWithoutSoneCausesAnError() throws FcpException {
-               Sone sone = mockLocalSone(core, "SoneId");
-               mockPost(core, sone, "PostId");
+               Sone sone = mocks.mockSone("SoneId").local().create();
+               mocks.mockPost(sone, "PostId").create();
                CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
-               when(core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
+               when(mocks.core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
                SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
                                .put("Message", "CreateReply")
                                .put("Post", "PostId")
@@ -98,9 +91,9 @@ public class CreateReplyCommandTest {
 
        @Test(expected = FcpException.class)
        public void verifyThatCreatingAReplyWithoutPostCausesAnError() throws FcpException {
-               mockLocalSone(core, "SoneId");
+               mocks.mockSone("SoneId").local().create();
                CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
-               when(core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
+               when(mocks.core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
                SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
                                .put("Message", "CreateReply")
                                .put("Sone", "SoneId")
@@ -111,10 +104,10 @@ public class CreateReplyCommandTest {
 
        @Test(expected = FcpException.class)
        public void verifyThatCreatingAReplyWithoutTextCausesAnError() throws FcpException {
-               Sone sone = mockLocalSone(core, "SoneId");
-               mockPost(core, sone, "PostId");
+               Sone sone = mocks.mockSone("SoneId").local().create();
+               mocks.mockPost(sone, "PostId").create();
                CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
-               when(core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
+               when(mocks.core.postReplyCreated()).thenReturn(Optional.<PostReplyCreated>of(capturingPostReplyCreated));
                SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
                                .put("Message", "CreateReply")
                                .put("Sone", "SoneId")