Add class that marks a post as known.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 12:04:57 +0000 (14:04 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 30 Jul 2014 12:04:57 +0000 (14:04 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java
src/test/java/net/pterodactylus/sone/core/CoreTest.java [new file with mode: 0644]

index c85d0e7..e99c157 100644 (file)
@@ -90,6 +90,7 @@ import net.pterodactylus.util.number.Numbers;
 import net.pterodactylus.util.service.AbstractService;
 import net.pterodactylus.util.thread.NamedThreadFactory;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicates;
 import com.google.common.collect.FluentIterable;
@@ -1396,16 +1397,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                eventBus.post(new NewPostFoundEvent(post));
                sone.addPost(post);
                touchConfiguration();
-               localElementTicker.schedule(new Runnable() {
-
-                       /**
-                        * {@inheritDoc}
-                        */
-                       @Override
-                       public void run() {
-                               markPostKnown(post);
-                       }
-               }, 10, TimeUnit.SECONDS);
+               localElementTicker.schedule(new MarkPostKnown(post), 10, TimeUnit.SECONDS);
                return post;
        }
 
@@ -2182,4 +2174,20 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                touchConfiguration();
        }
 
+       @VisibleForTesting
+       class MarkPostKnown implements Runnable {
+
+               private final Post post;
+
+               public MarkPostKnown(Post post) {
+                       this.post = post;
+               }
+
+               @Override
+               public void run() {
+                       markPostKnown(post);
+               }
+
+       }
+
 }
diff --git a/src/test/java/net/pterodactylus/sone/core/CoreTest.java b/src/test/java/net/pterodactylus/sone/core/CoreTest.java
new file mode 100644 (file)
index 0000000..4d32298
--- /dev/null
@@ -0,0 +1,28 @@
+package net.pterodactylus.sone.core;
+
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import net.pterodactylus.sone.core.Core.MarkPostKnown;
+import net.pterodactylus.sone.data.Post;
+
+import org.junit.Test;
+
+/**
+ * Unit test for {@link Core} and its subclasses.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class CoreTest {
+
+       @Test
+       public void markPostKnownMarksPostAsKnown() {
+               Core core = mock(Core.class);
+               Post post = mock(Post.class);
+               MarkPostKnown markPostKnown = core.new MarkPostKnown(post);
+               markPostKnown.run();
+               verify(core).markPostKnown(eq(post));
+       }
+
+}