From 84b0cda5e125223b215f61f8d541ece42025d30d Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 30 Jul 2014 14:04:57 +0200 Subject: [PATCH] Add class that marks a post as known. --- .../java/net/pterodactylus/sone/core/Core.java | 28 ++++++++++++++-------- .../java/net/pterodactylus/sone/core/CoreTest.java | 28 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 src/test/java/net/pterodactylus/sone/core/CoreTest.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index c85d0e7..e99c157 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -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 index 0000000..4d32298 --- /dev/null +++ b/src/test/java/net/pterodactylus/sone/core/CoreTest.java @@ -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 David ‘Bombe’ Roden + */ +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)); + } + +} -- 2.7.4