From 38aaaed4fa2430f157c024dd7eb0977289be1198 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 30 Oct 2013 20:46:04 +0100 Subject: [PATCH] =?utf8?q?Mock=20a=20Sone=E2=80=99s=20friends=20in=20a=20b?= =?utf8?q?etter=20way.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/test/java/net/pterodactylus/sone/data/Mocks.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/test/java/net/pterodactylus/sone/data/Mocks.java b/src/test/java/net/pterodactylus/sone/data/Mocks.java index ce95638..0aa6035 100644 --- a/src/test/java/net/pterodactylus/sone/data/Mocks.java +++ b/src/test/java/net/pterodactylus/sone/data/Mocks.java @@ -23,6 +23,7 @@ import static com.google.common.base.Optional.of; import static com.google.common.collect.ArrayListMultimap.create; import static com.google.common.collect.Ordering.from; import static com.google.common.collect.Sets.newHashSet; +import static java.util.Collections.emptySet; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -103,7 +104,7 @@ public class Mocks { private Optional name = absent(); private long time; private Profile profile = new Profile(mockedSone); - private Optional friend = absent(); + private Collection friends = emptySet(); private SoneMocker(String id) { this.id = id; @@ -134,8 +135,8 @@ public class Mocks { return this; } - public SoneMocker withFriends(String friend) { - this.friend = fromNullable(friend); + public SoneMocker withFriends(Collection friends) { + this.friends = friends; return this; } @@ -156,9 +157,13 @@ public class Mocks { } }); when(mockedSone.hasFriend(anyString())).thenReturn(false); - if (friend.isPresent()) { - when(mockedSone.hasFriend(friend.get())).thenReturn(true); - } + when(mockedSone.getFriends()).thenReturn(friends); + when(mockedSone.hasFriend(anyString())).then(new Answer() { + @Override + public Boolean answer(InvocationOnMock invocation) throws Throwable { + return friends.contains(invocation.getArguments()[0]); + } + }); } else { when(mockedSone.newPostBuilder()).thenThrow(IllegalStateException.class); when(mockedSone.newPostReplyBuilder(anyString())).thenThrow(IllegalStateException.class); -- 2.7.4