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;
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;
private final Multimap<Sone, Post> sonePosts = create();
private final Map<String, Sone> sones = newHashMap();
+ private Optional<Sone> currentSone = absent();
private final Map<String, Post> posts = newHashMap();
private final Multimap<Post, PostReply> postReplies = create();
private final Multimap<String, Post> directedPosts = create();
return (soneId == null) ? Optional.<Sone>absent() : fromNullable(sones.get(soneId));
}
});
+ Answer<Sone> returnCurrentSone = new Answer<Sone>() {
+ @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<Collection<Sone>>() {
@Override
public Collection<Sone> answer(InvocationOnMock invocation) throws Throwable {
private final Sone mockedSone = mock(Sone.class);
private final String id;
private boolean local;
+ private boolean current;
private Optional<String> name = absent();
private long time;
private Profile profile = new Profile(mockedSone);
return this;
}
+ public SoneMocker current() {
+ current = true;
+ return this;
+ }
+
public SoneMocker withName(String name) {
this.name = fromNullable(name);
return this;
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());
}