projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e6261cf
)
Turn Mocks into a stateful object.
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Mon, 28 Oct 2013 21:08:18 +0000
(22:08 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:48 +0000
(22:25 +0100)
src/test/java/net/pterodactylus/sone/data/Mocks.java
patch
|
blob
|
history
src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java
patch
|
blob
|
history
src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java
patch
|
blob
|
history
src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java
patch
|
blob
|
history
src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java
patch
|
blob
|
history
diff --git
a/src/test/java/net/pterodactylus/sone/data/Mocks.java
b/src/test/java/net/pterodactylus/sone/data/Mocks.java
index
5181f04
..
d75f5f6
100644
(file)
--- a/
src/test/java/net/pterodactylus/sone/data/Mocks.java
+++ b/
src/test/java/net/pterodactylus/sone/data/Mocks.java
@@
-47,16
+47,23
@@
import org.mockito.stubbing.Answer;
*/
public class Mocks {
*/
public class Mocks {
- private static final Multimap<Sone, Post> sonePosts = create();
+ private final Multimap<Sone, Post> sonePosts = create();
+ public final Database database;
+ public final Core core;
- public static Core mockCore(Database database) {
+ public Mocks() {
+ database = mockDatabase();
+ core = mockCore(database);
+ }
+
+ private static Core mockCore(Database database) {
Core core = mock(Core.class);
when(core.getDatabase()).thenReturn(database);
when(core.getSone(anyString())).thenReturn(Optional.<Sone>absent());
return core;
}
Core core = mock(Core.class);
when(core.getDatabase()).thenReturn(database);
when(core.getSone(anyString())).thenReturn(Optional.<Sone>absent());
return core;
}
- p
ublic
static Database mockDatabase() {
+ p
rivate
static Database mockDatabase() {
Database database = mock(Database.class);
when(database.getSone(anyString())).thenReturn(Optional.<Sone>absent());
when(database.getPost(anyString())).thenReturn(Optional.<Post>absent());
Database database = mock(Database.class);
when(database.getSone(anyString())).thenReturn(Optional.<Sone>absent());
when(database.getPost(anyString())).thenReturn(Optional.<Post>absent());
@@
-64,12
+71,11
@@
public class Mocks {
return database;
}
return database;
}
- public
static Sone mockLocalSone(Core core,
final String id) {
+ public
Sone mockLocalSone(
final String id) {
final Sone sone = mock(Sone.class);
when(sone.getId()).thenReturn(id);
when(sone.isLocal()).thenReturn(true);
when(sone.getProfile()).thenReturn(new Profile(sone));
final Sone sone = mock(Sone.class);
when(sone.getId()).thenReturn(id);
when(sone.isLocal()).thenReturn(true);
when(sone.getProfile()).thenReturn(new Profile(sone));
- final Database database = core.getDatabase();
when(sone.newPostBuilder()).thenReturn(new DefaultPostBuilder(database, id));
when(sone.newPostReplyBuilder(anyString())).then(new Answer<PostReplyBuilder>() {
@Override
when(sone.newPostBuilder()).thenReturn(new DefaultPostBuilder(database, id));
when(sone.newPostReplyBuilder(anyString())).then(new Answer<PostReplyBuilder>() {
@Override
@@
-88,12
+94,11
@@
public class Mocks {
return sone;
}
return sone;
}
- public
static Sone mockRemoteSone(Core core,
final String id) {
+ public
Sone mockRemoteSone(
final String id) {
final Sone sone = mock(Sone.class);
when(sone.getId()).thenReturn(id);
when(sone.isLocal()).thenReturn(false);
when(sone.getProfile()).thenReturn(new Profile(sone));
final Sone sone = mock(Sone.class);
when(sone.getId()).thenReturn(id);
when(sone.isLocal()).thenReturn(false);
when(sone.getProfile()).thenReturn(new Profile(sone));
- final Database database = core.getDatabase();
when(sone.newPostBuilder()).thenThrow(IllegalStateException.class);
when(sone.newPostReplyBuilder(Matchers.<String>anyObject())).thenThrow(IllegalStateException.class);
when(core.getSone(eq(id))).thenReturn(of(sone));
when(sone.newPostBuilder()).thenThrow(IllegalStateException.class);
when(sone.newPostReplyBuilder(Matchers.<String>anyObject())).thenThrow(IllegalStateException.class);
when(core.getSone(eq(id))).thenReturn(of(sone));
@@
-107,21
+112,19
@@
public class Mocks {
return sone;
}
return sone;
}
- public
static Post mockPost(Core core,
Sone sone, String postId) {
+ public
Post mockPost(
Sone sone, String postId) {
Post post = mock(Post.class);
when(post.getId()).thenReturn(postId);
when(post.getSone()).thenReturn(sone);
Post post = mock(Post.class);
when(post.getId()).thenReturn(postId);
when(post.getSone()).thenReturn(sone);
- Database database = core.getDatabase();
when(database.getPost(eq(postId))).thenReturn(of(post));
sonePosts.put(sone, post);
return post;
}
when(database.getPost(eq(postId))).thenReturn(of(post));
sonePosts.put(sone, post);
return post;
}
- public
static PostReply mockPostReply(Core core,
Sone sone, String replyId) {
+ public
PostReply mockPostReply(
Sone sone, String replyId) {
PostReply postReply = mock(PostReply.class);
when(postReply.getId()).thenReturn(replyId);
when(postReply.getSone()).thenReturn(sone);
PostReply postReply = mock(PostReply.class);
when(postReply.getId()).thenReturn(replyId);
when(postReply.getSone()).thenReturn(sone);
- Database database = core.getDatabase();
when(database.getPostReply(eq(replyId))).thenReturn(of(postReply));
return postReply;
}
when(database.getPostReply(eq(replyId))).thenReturn(of(postReply));
return postReply;
}
diff --git
a/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java
b/src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java
index
5af1e7e
..
6cc6f61
100644
(file)
--- a/
src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java
+++ b/
src/test/java/net/pterodactylus/sone/fcp/CreatePostCommandTest.java
@@
-19,9
+19,6
@@
package net.pterodactylus.sone.fcp;
import static com.google.common.base.Optional.of;
import static java.lang.System.currentTimeMillis;
import static com.google.common.base.Optional.of;
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.database.PostBuilder.PostCreated;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static net.pterodactylus.sone.database.PostBuilder.PostCreated;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
@@
-33,10
+30,9
@@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.when;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Mockito.when;
-import net.pterodactylus.sone.
core.Core
;
+import net.pterodactylus.sone.
data.Mocks
;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
import net.pterodactylus.sone.freenet.fcp.FcpException;
@@
-54,16
+50,15
@@
import org.junit.Test;
public class CreatePostCommandTest {
private final long now = currentTimeMillis();
public class CreatePostCommandTest {
private final long now = currentTimeMillis();
- private final Database database = mockDatabase();
- private final Core core = mockCore(database);
- private final CreatePostCommand createPostCommand = new CreatePostCommand(core);
+ private final Mocks mocks = new Mocks();
+ private final CreatePostCommand createPostCommand = new CreatePostCommand(mocks.core);
@Test
public void verifyThatCreatingAPostWorks() throws FcpException {
@Test
public void verifyThatCreatingAPostWorks() throws FcpException {
- Sone sone = mock
LocalSone(core,
"Sone");
- mock
LocalSone(core,
"OtherSone");
+ Sone sone = mock
s.mockLocalSone(
"Sone");
+ mock
s.mockLocalSone(
"OtherSone");
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
- when(core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
+ when(
mocks.
core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
@@
-83,9
+78,9
@@
public class CreatePostCommandTest {
@Test
public void verifyThatCreatingAPostWithoutRecipientWorks() throws FcpException {
@Test
public void verifyThatCreatingAPostWithoutRecipientWorks() throws FcpException {
- Sone sone = mock
LocalSone(core,
"Sone");
+ Sone sone = mock
s.mockLocalSone(
"Sone");
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
- when(core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
+ when(
mocks.
core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
@@
-104,9
+99,9
@@
public class CreatePostCommandTest {
@Test
public void verifyThatCreatingAPostDirectedToTheSendingSoneCausesAnError() throws FcpException {
@Test
public void verifyThatCreatingAPostDirectedToTheSendingSoneCausesAnError() throws FcpException {
- mock
LocalSone(core,
"Sone");
+ mock
s.mockLocalSone(
"Sone");
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
- when(core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
+ when(
mocks.
core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
@@
-121,9
+116,9
@@
public class CreatePostCommandTest {
@Test(expected = FcpException.class)
public void verifyThatCreatingAPostWithoutTextCausesAnError() throws FcpException {
@Test(expected = FcpException.class)
public void verifyThatCreatingAPostWithoutTextCausesAnError() throws FcpException {
- mock
LocalSone(core,
"Sone");
+ mock
s.mockLocalSone(
"Sone");
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
- when(core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
+ when(
mocks.
core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Sone", "Sone")
@@
-133,9
+128,9
@@
public class CreatePostCommandTest {
@Test(expected = FcpException.class)
public void verifyThatCreatingAPostWithoutSoneCausesAnError() throws FcpException {
@Test(expected = FcpException.class)
public void verifyThatCreatingAPostWithoutSoneCausesAnError() throws FcpException {
- mock
LocalSone(core,
"Sone");
+ mock
s.mockLocalSone(
"Sone");
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
CapturingPostCreated capturingPostCreated = new CapturingPostCreated();
- when(core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
+ when(
mocks.
core.postCreated()).thenReturn(Optional.<PostCreated>of(capturingPostCreated));
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Text", "Text of the post.")
SimpleFieldSet createPostFieldSet = new SimpleFieldSetBuilder()
.put("Text", "Text of the post.")
diff --git
a/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java
b/src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java
index
6317c8f
..
70f9996
100644
(file)
--- a/
src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java
+++ b/
src/test/java/net/pterodactylus/sone/fcp/CreateReplyCommandTest.java
@@
-18,10
+18,6
@@
package net.pterodactylus.sone.fcp;
import static java.lang.System.currentTimeMillis;
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.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@@
-31,10
+27,9
@@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.core.AllOf.allOf;
import static org.mockito.Mockito.when;
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.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;
import net.pterodactylus.sone.database.PostReplyBuilder.PostReplyCreated;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
@@
-53,16
+48,15
@@
import org.junit.Test;
public class CreateReplyCommandTest {
private final long now = currentTimeMillis();
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 {
@Test
public void verifyThatCreatingAFullySpecifiedReplyWorks() throws FcpException {
- Sone sone = mock
LocalSone(core,
"SoneId");
- mock
Post(core,
sone, "PostId");
+ Sone sone = mock
s.mockLocalSone(
"SoneId");
+ mock
s.mockPost(
sone, "PostId");
CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
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")
SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "CreateReply")
.put("Sone", "SoneId")
@@
-84,10
+78,10
@@
public class CreateReplyCommandTest {
@Test(expected = FcpException.class)
public void verifyThatCreatingAReplyWithoutSoneCausesAnError() throws FcpException {
@Test(expected = FcpException.class)
public void verifyThatCreatingAReplyWithoutSoneCausesAnError() throws FcpException {
- Sone sone = mock
LocalSone(core,
"SoneId");
- mock
Post(core,
sone, "PostId");
+ Sone sone = mock
s.mockLocalSone(
"SoneId");
+ mock
s.mockPost(
sone, "PostId");
CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
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")
SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "CreateReply")
.put("Post", "PostId")
@@
-98,9
+92,9
@@
public class CreateReplyCommandTest {
@Test(expected = FcpException.class)
public void verifyThatCreatingAReplyWithoutPostCausesAnError() throws FcpException {
@Test(expected = FcpException.class)
public void verifyThatCreatingAReplyWithoutPostCausesAnError() throws FcpException {
- mock
LocalSone(core,
"SoneId");
+ mock
s.mockLocalSone(
"SoneId");
CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
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")
SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "CreateReply")
.put("Sone", "SoneId")
@@
-111,10
+105,10
@@
public class CreateReplyCommandTest {
@Test(expected = FcpException.class)
public void verifyThatCreatingAReplyWithoutTextCausesAnError() throws FcpException {
@Test(expected = FcpException.class)
public void verifyThatCreatingAReplyWithoutTextCausesAnError() throws FcpException {
- Sone sone = mock
LocalSone(core,
"SoneId");
- mock
Post(core,
sone, "PostId");
+ Sone sone = mock
s.mockLocalSone(
"SoneId");
+ mock
s.mockPost(
sone, "PostId");
CapturingPostReplyCreated capturingPostReplyCreated = new CapturingPostReplyCreated();
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")
SimpleFieldSet createReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "CreateReply")
.put("Sone", "SoneId")
diff --git
a/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java
b/src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java
index
1d282ca
..
5b06277
100644
(file)
--- a/
src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java
+++ b/
src/test/java/net/pterodactylus/sone/fcp/DeletePostCommandTest.java
@@
-17,11
+17,6
@@
package net.pterodactylus.sone.fcp;
package net.pterodactylus.sone.fcp;
-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.data.Mocks.mockRemoteSone;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@@
-29,10
+24,9
@@
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.Mockito.doNothing;
import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.Mockito.doNothing;
-import net.pterodactylus.sone.
core.Core
;
+import net.pterodactylus.sone.
data.Mocks
;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
import net.pterodactylus.sone.freenet.fcp.FcpException;
@@
-49,16
+43,15
@@
import org.mockito.ArgumentCaptor;
*/
public class DeletePostCommandTest {
*/
public class DeletePostCommandTest {
- private final Database database = mockDatabase();
- private final Core core = mockCore(database);
- private final DeletePostCommand deletePostCommand = new DeletePostCommand(core);
+ private final Mocks mocks = new Mocks();
+ private final DeletePostCommand deletePostCommand = new DeletePostCommand(mocks.core);
@Test
public void verifyThatDeletingAPostWorks() throws FcpException {
@Test
public void verifyThatDeletingAPostWorks() throws FcpException {
- Sone sone = mock
LocalSone(core,
"Sone");
- Post post = mock
Post(core,
sone, "PostId");
+ Sone sone = mock
s.mockLocalSone(
"Sone");
+ Post post = mock
s.mockPost(
sone, "PostId");
ArgumentCaptor<Post> deletedPost = forClass(Post.class);
ArgumentCaptor<Post> deletedPost = forClass(Post.class);
- doNothing().when(core).deletePost(deletedPost.capture());
+ doNothing().when(
mocks.
core).deletePost(deletedPost.capture());
SimpleFieldSet deletePostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeletePost")
.put("Post", "PostId")
SimpleFieldSet deletePostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeletePost")
.put("Post", "PostId")
@@
-72,8
+65,8
@@
public class DeletePostCommandTest {
@Test
public void verifyThatDeletingAPostFromANonLocalSoneCausesAnError() throws FcpException {
@Test
public void verifyThatDeletingAPostFromANonLocalSoneCausesAnError() throws FcpException {
- Sone sone = mock
RemoteSone(core,
"Sone");
- Post post = mock
Post(core,
sone, "PostId");
+ Sone sone = mock
s.mockRemoteSone(
"Sone");
+ Post post = mock
s.mockPost(
sone, "PostId");
SimpleFieldSet deletePostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeletePost")
.put("Post", "PostId")
SimpleFieldSet deletePostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeletePost")
.put("Post", "PostId")
@@
-95,8
+88,8
@@
public class DeletePostCommandTest {
@Test(expected = FcpException.class)
public void verifyThatDeletingAPostWithAnInvalidPostIdCausesAnError() throws FcpException {
@Test(expected = FcpException.class)
public void verifyThatDeletingAPostWithAnInvalidPostIdCausesAnError() throws FcpException {
- Sone sone = mock
LocalSone(core,
"Sone");
- mock
Post(core,
sone, "PostId");
+ Sone sone = mock
s.mockLocalSone(
"Sone");
+ mock
s.mockPost(
sone, "PostId");
SimpleFieldSet deletePostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeletePost")
.put("Post", "OtherPostId")
SimpleFieldSet deletePostFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeletePost")
.put("Post", "OtherPostId")
diff --git
a/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java
b/src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java
index
4ab8cdf
..
422a470
100644
(file)
--- a/
src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java
+++ b/
src/test/java/net/pterodactylus/sone/fcp/DeleteReplyCommandTest.java
@@
-17,11
+17,6
@@
package net.pterodactylus.sone.fcp;
package net.pterodactylus.sone.fcp;
-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.mockPostReply;
-import static net.pterodactylus.sone.data.Mocks.mockRemoteSone;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static net.pterodactylus.sone.freenet.fcp.Command.AccessType.DIRECT;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
@@
-29,10
+24,9
@@
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.Mockito.doNothing;
import static org.mockito.ArgumentCaptor.forClass;
import static org.mockito.Mockito.doNothing;
-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.data.PostReply;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.database.Database;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import net.pterodactylus.sone.freenet.SimpleFieldSetBuilder;
import net.pterodactylus.sone.freenet.fcp.Command.Response;
import net.pterodactylus.sone.freenet.fcp.FcpException;
@@
-49,16
+43,15
@@
import org.mockito.ArgumentCaptor;
*/
public class DeleteReplyCommandTest {
*/
public class DeleteReplyCommandTest {
- private final Database database = mockDatabase();
- private final Core core = mockCore(database);
- private final DeleteReplyCommand deleteReplyCommand = new DeleteReplyCommand(core);
+ private final Mocks mocks = new Mocks();
+ private final DeleteReplyCommand deleteReplyCommand = new DeleteReplyCommand(mocks.core);
@Test
public void verifyThatDeletingAReplyWorks() throws FcpException {
@Test
public void verifyThatDeletingAReplyWorks() throws FcpException {
- Sone sone = mock
LocalSone(core,
"SoneId");
- PostReply postReply = mock
PostReply(core,
sone, "ReplyId");
+ Sone sone = mock
s.mockLocalSone(
"SoneId");
+ PostReply postReply = mock
s.mockPostReply(
sone, "ReplyId");
ArgumentCaptor<PostReply> postReplyCaptor = forClass(PostReply.class);
ArgumentCaptor<PostReply> postReplyCaptor = forClass(PostReply.class);
- doNothing().when(core).deleteReply(postReplyCaptor.capture());
+ doNothing().when(
mocks.
core).deleteReply(postReplyCaptor.capture());
SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeleteReply")
.put("Reply", "ReplyId")
SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeleteReply")
.put("Reply", "ReplyId")
@@
-89,8
+82,8
@@
public class DeleteReplyCommandTest {
@Test
public void verifyThatDeletingAReplyFromANonLocalSoneCausesAnError() throws FcpException {
@Test
public void verifyThatDeletingAReplyFromANonLocalSoneCausesAnError() throws FcpException {
- Sone sone = mock
RemoteSone(core,
"SoneId");
- mock
PostReply(core,
sone, "ReplyId");
+ Sone sone = mock
s.mockRemoteSone(
"SoneId");
+ mock
s.mockPostReply(
sone, "ReplyId");
SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeleteReply")
.put("Reply", "ReplyId")
SimpleFieldSet deleteReplyFieldSet = new SimpleFieldSetBuilder()
.put("Message", "DeleteReply")
.put("Reply", "ReplyId")