From b88e3d99a937f44e584567d965f4870c35727407 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 28 Oct 2013 22:10:49 +0100 Subject: [PATCH] Use method for common mocked Sone initialization. --- .../java/net/pterodactylus/sone/data/Mocks.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/test/java/net/pterodactylus/sone/data/Mocks.java b/src/test/java/net/pterodactylus/sone/data/Mocks.java index d75f5f6..dd5cf69 100644 --- a/src/test/java/net/pterodactylus/sone/data/Mocks.java +++ b/src/test/java/net/pterodactylus/sone/data/Mocks.java @@ -73,9 +73,8 @@ public class Mocks { 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)); + initializeSoneMock(id, sone); when(sone.newPostBuilder()).thenReturn(new DefaultPostBuilder(database, id)); when(sone.newPostReplyBuilder(anyString())).then(new Answer() { @Override @@ -83,24 +82,21 @@ public class Mocks { return new DefaultPostReplyBuilder(database, id, (String) invocation.getArguments()[0]); } }); - when(core.getSone(eq(id))).thenReturn(of(sone)); - when(database.getSone(eq(id))).thenReturn(of(sone)); - when(sone.getPosts()).then(new Answer>() { - @Override - public List answer(InvocationOnMock invocationOnMock) throws Throwable { - return from(TIME_COMPARATOR).sortedCopy(sonePosts.get(sone)); - } - }); return sone; } 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)); + initializeSoneMock(id, sone); when(sone.newPostBuilder()).thenThrow(IllegalStateException.class); when(sone.newPostReplyBuilder(Matchers.anyObject())).thenThrow(IllegalStateException.class); + return sone; + } + + private void initializeSoneMock(String id, final Sone sone) { + when(sone.getId()).thenReturn(id); + when(sone.getProfile()).thenReturn(new Profile(sone)); when(core.getSone(eq(id))).thenReturn(of(sone)); when(database.getSone(eq(id))).thenReturn(of(sone)); when(sone.getPosts()).then(new Answer>() { @@ -109,7 +105,6 @@ public class Mocks { return from(TIME_COMPARATOR).sortedCopy(sonePosts.get(sone)); } }); - return sone; } public Post mockPost(Sone sone, String postId) { -- 2.7.4