Add class to fetch a Sone.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 11:59:46 +0000 (13:59 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 11:59:46 +0000 (13:59 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java [new file with mode: 0644]

index c9ac93b..c85d0e7 100644 (file)
@@ -799,15 +799,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                                }
                        }
                        soneDownloader.addSone(sone);
-                       soneDownloaders.execute(new Runnable() {
-
-                               @Override
-                               @SuppressWarnings("synthetic-access")
-                               public void run() {
-                                       soneDownloader.fetchSone(sone, sone.getRequestUri());
-                               }
-
-                       });
+                       soneDownloaders.execute(soneDownloader.new FetchSone(sone));
                        return sone;
                }
        }
index 53eef16..8b3ad79 100644 (file)
@@ -533,4 +533,19 @@ public class SoneDownloader extends AbstractService {
                }
        }
 
+       public class FetchSone implements Runnable {
+
+               private final Sone sone;
+
+               public FetchSone(Sone sone) {
+                       this.sone = sone;
+               }
+
+               @Override
+               public void run() {
+                       fetchSone(sone, sone.getRequestUri());
+               }
+
+       }
+
 }
diff --git a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java
new file mode 100644 (file)
index 0000000..413b8ff
--- /dev/null
@@ -0,0 +1,33 @@
+package net.pterodactylus.sone.core;
+
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import net.pterodactylus.sone.core.SoneDownloader.FetchSone;
+import net.pterodactylus.sone.data.Sone;
+
+import freenet.keys.FreenetURI;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link SoneDownloader} and its subclasses.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class SoneDownloaderTest {
+
+       @Test
+       public void fetchSoneDownloadsSone() {
+               SoneDownloader soneDownloader = mock(SoneDownloader.class);
+               Sone sone = mock(Sone.class);
+               FreenetURI soneUri = mock(FreenetURI.class);
+               when(sone.getRequestUri()).thenReturn(soneUri);
+               FetchSone fetchSone = soneDownloader.new FetchSone(sone);
+               fetchSone.run();
+               verify(soneDownloader).fetchSone(eq(sone), eq(soneUri));
+       }
+
+}