From 94088d808dfca4bf5464ee4f3b099175fb4c058a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 30 Jul 2014 13:59:46 +0200 Subject: [PATCH] Add class to fetch a Sone. --- .../java/net/pterodactylus/sone/core/Core.java | 10 +------ .../pterodactylus/sone/core/SoneDownloader.java | 15 ++++++++++ .../sone/core/SoneDownloaderTest.java | 33 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java 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)); + } + +} -- 2.7.4