From f9ec36b55750b14c7aec195e7f3ff092a570003d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 31 Jul 2014 21:20:04 +0200 Subject: [PATCH] Add class that fetches a Sone. --- .../java/net/pterodactylus/sone/core/Core.java | 25 ++++++++-------------- .../pterodactylus/sone/core/SoneDownloader.java | 15 +++++++++++++ .../sone/core/SoneDownloaderTest.java | 10 +++++++++ 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index b9fb766..b6a0a90 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -2090,22 +2090,15 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, */ @Subscribe public void identityUpdated(IdentityUpdatedEvent identityUpdatedEvent) { - final Identity identity = identityUpdatedEvent.identity(); - soneDownloaders.execute(new Runnable() { - - @Override - @SuppressWarnings("synthetic-access") - public void run() { - Sone sone = getRemoteSone(identity.getId(), false); - if (sone.isLocal()) { - return; - } - sone.setIdentity(identity); - sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), sone.getLatestEdition())); - soneDownloader.addSone(sone); - soneDownloader.fetchSone(sone); - } - }); + Identity identity = identityUpdatedEvent.identity(); + final Sone sone = getRemoteSone(identity.getId(), false); + if (sone.isLocal()) { + return; + } + sone.setIdentity(identity); + sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), sone.getLatestEdition())); + soneDownloader.addSone(sone); + soneDownloaders.execute(soneDownloader.new FetchSone(sone)); } /** diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 8f4bf7d..7fc3a32 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -548,4 +548,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); + } + + } + } diff --git a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java index 73920ff..21d01f6 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneDownloaderTest.java @@ -5,6 +5,7 @@ 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.core.SoneDownloader.FetchSoneWithUri; import net.pterodactylus.sone.data.Sone; @@ -30,4 +31,13 @@ public class SoneDownloaderTest { verify(soneDownloader).fetchSone(eq(sone), eq(soneUri)); } + @Test + public void fetchSoneDownloadsSone() { + SoneDownloader soneDownloader = mock(SoneDownloader.class); + Sone sone = mock(Sone.class); + FetchSone fetchSone = soneDownloader.new FetchSone(sone); + fetchSone.run(); + verify(soneDownloader).fetchSone(eq(sone)); + } + } -- 2.7.4