Implement getLocalSone in mocked Core.
[Sone.git] / src / test / java / net / pterodactylus / sone / data / Mocks.java
index e4449c4..f56a1d4 100644 (file)
@@ -101,6 +101,13 @@ public class Mocks {
                                return sones.values();
                        }
                });
+               when(core.getLocalSone(anyString())).then(new Answer<Optional<Sone>>() {
+                       @Override
+                       public Optional<Sone> answer(InvocationOnMock invocation) throws Throwable {
+                               Sone localSone = sones.get(invocation.getArguments()[0]);
+                               return ((localSone == null) || (!localSone.isLocal())) ? Optional.<Sone>absent() : of(localSone);
+                       }
+               });
                when(core.getLocalSones()).then(new Answer<Collection<Sone>>() {
                        @Override
                        public Collection<Sone> answer(InvocationOnMock invocation) throws Throwable {
@@ -166,8 +173,10 @@ public class Mocks {
                return new PostReplyMocker(replyId, sone);
        }
 
-       public FreenetRequest mockRequest(String path) throws URISyntaxException {
-               HTTPRequest httpRequest = new HTTPRequestImpl(new URI(path), "GET");
+       public FreenetRequest mockRequest(String path) {
+               HTTPRequest httpRequest = mock(HTTPRequest.class);
+               when(httpRequest.getMethod()).thenReturn("GET");
+               when(httpRequest.getPath()).thenReturn(path);
                FreenetRequest request = mock(FreenetRequest.class);
                when(request.getHttpRequest()).thenReturn(httpRequest);
                return request;