X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FCreatePostCommandTest.java;h=05aedaa3617944b1762ada882c181a4f890913eb;hb=2d37242d19f2e726cd402b99f935a0eba282f630;hp=6cc6f613da564e4ef737209c68cc28f951a7e847;hpb=844bd06ee895aa3a050192b5063b1efe1a85f80b;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java b/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java index 6cc6f61..05aedaa 100644 --- a/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java +++ b/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java @@ -20,13 +20,13 @@ 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.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; @@ -55,8 +55,8 @@ public class CreatePostCommandTest { @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.of(capturingPostCreated)); @@ -66,9 +66,7 @@ public class CreatePostCommandTest { .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"))); @@ -78,7 +76,7 @@ public class CreatePostCommandTest { @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.of(capturingPostCreated)); @@ -87,9 +85,7 @@ public class CreatePostCommandTest { .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.absent())); @@ -99,7 +95,7 @@ public class CreatePostCommandTest { @Test public void verifyThatCreatingAPostDirectedToTheSendingSoneCausesAnError() throws FcpException { - mocks.mockLocalSone("Sone"); + mocks.mockSone("Sone").local().create(); CapturingPostCreated capturingPostCreated = new CapturingPostCreated(); when(mocks.core.postCreated()).thenReturn(Optional.of(capturingPostCreated)); @@ -109,14 +105,13 @@ public class CreatePostCommandTest { .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.of(capturingPostCreated)); @@ -128,7 +123,7 @@ public class CreatePostCommandTest { @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.of(capturingPostCreated));