From: David ‘Bombe’ Roden Date: Thu, 31 Jul 2014 19:20:04 +0000 (+0200) Subject: Add class that fetches a Sone. X-Git-Tag: 0.9-rc1^2~3^2~187 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=f9ec36b55750b14c7aec195e7f3ff092a570003d;p=Sone.git Add class that fetches 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 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)); + } + }