From 58e71083db32980d249c61fa6ddc7645256576e8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 19 Feb 2014 18:14:00 +0100 Subject: [PATCH] Add concept of a current Sone. --- .../java/net/pterodactylus/sone/data/Mocks.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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()); } -- 2.7.4