Add class that fetches a Sone.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 31 Jul 2014 19:20:04 +0000 (21:20 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 31 Jul 2014 19:20:04 +0000 (21:20 +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

index b9fb766..b6a0a90 100644 (file)
@@ -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));
        }
 
        /**
index 8f4bf7d..7fc3a32 100644 (file)
@@ -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);
+               }
+
+       }
+
 }
index 73920ff..21d01f6 100644 (file)
@@ -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));
+       }
+
 }