From: David ‘Bombe’ Roden Date: Wed, 30 Jul 2014 11:59:46 +0000 (+0200) Subject: Add class to fetch a Sone. X-Git-Tag: 0.9-rc1^2~3^2~199 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=94088d808dfca4bf5464ee4f3b099175fb4c058a;p=Sone.git Add class to fetch a Sone. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index c9ac93b..c85d0e7 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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; } } diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 53eef16..8b3ad79 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -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 index 0000000..413b8ff --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java @@ -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 David ‘Bombe’ Roden + */ +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)); + } + +}