From: David ‘Bombe’ Roden Date: Wed, 19 Feb 2014 17:14:00 +0000 (+0100) Subject: Add concept of a current Sone. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=58e71083db32980d249c61fa6ddc7645256576e8;p=Sone.git Add concept of a current Sone. --- diff --git a/src/test/java/net/pterodactylus/sone/data/Mocks.java b/src/test/java/net/pterodactylus/sone/data/Mocks.java index 3615828..51fa239 100644 --- a/src/test/java/net/pterodactylus/sone/data/Mocks.java +++ b/src/test/java/net/pterodactylus/sone/data/Mocks.java @@ -24,6 +24,8 @@ import static com.google.common.collect.ArrayListMultimap.create; import static com.google.common.collect.Maps.newHashMap; import static com.google.common.collect.Ordering.from; import static java.util.Collections.emptySet; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; @@ -55,6 +57,8 @@ import net.pterodactylus.sone.web.WebInterface; import net.pterodactylus.sone.web.page.FreenetRequest; import freenet.clients.http.HTTPRequestImpl; +import freenet.clients.http.SessionManager.Session; +import freenet.clients.http.ToadletContext; import freenet.support.api.HTTPRequest; import com.google.common.base.Function; @@ -78,6 +82,7 @@ public class Mocks { private final Multimap sonePosts = create(); private final Map sones = newHashMap(); + private Optional currentSone = absent(); private final Map posts = newHashMap(); private final Multimap postReplies = create(); private final Multimap directedPosts = create(); @@ -97,6 +102,14 @@ public class Mocks { return (soneId == null) ? Optional.absent() : fromNullable(sones.get(soneId)); } }); + Answer returnCurrentSone = new Answer() { + @Override + public Sone answer(InvocationOnMock invocation) throws Throwable { + return currentSone.orNull(); + } + }; + when(webInterface.getCurrentSone(any(ToadletContext.class))).then(returnCurrentSone); + when(webInterface.getCurrentSone(any(Session.class))).then(returnCurrentSone); when(core.getSones()).then(new Answer>() { @Override public Collection answer(InvocationOnMock invocation) throws Throwable { @@ -201,6 +214,7 @@ public class Mocks { private final Sone mockedSone = mock(Sone.class); private final String id; private boolean local; + private boolean current; private Optional name = absent(); private long time; private Profile profile = new Profile(mockedSone); @@ -215,6 +229,11 @@ public class Mocks { return this; } + public SoneMocker current() { + current = true; + return this; + } + public SoneMocker withName(String name) { this.name = fromNullable(name); return this; @@ -243,6 +262,9 @@ public class Mocks { public Sone create() { when(mockedSone.getId()).thenReturn(id); when(mockedSone.isLocal()).thenReturn(local); + if (current) { + currentSone = of(mockedSone); + } if (name.isPresent()) { when(mockedSone.getName()).thenReturn(name.get()); }