From: David ‘Bombe’ Roden Date: Wed, 30 Oct 2013 19:46:04 +0000 (+0100) Subject: Mock a Sone’s friends in a better way. X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=38aaaed4fa2430f157c024dd7eb0977289be1198 Mock a Sone’s friends in a better way. --- 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);