X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCoreTest.java;h=66ef7437b3482782221a363a3e5d8bccb45c472c;hb=e3da46d8947ab8a542a156069b3b24c13fd011df;hp=263c2d0a64540874ac146b79a2b8b73a28adad5f;hpb=f229fe41f708d2b275c20ceb9aba5993761218a3;p=Sone.git
diff --git a/src/test/java/net/pterodactylus/sone/core/CoreTest.java b/src/test/java/net/pterodactylus/sone/core/CoreTest.java
index 263c2d0..66ef743 100644
--- a/src/test/java/net/pterodactylus/sone/core/CoreTest.java
+++ b/src/test/java/net/pterodactylus/sone/core/CoreTest.java
@@ -1,20 +1,38 @@
package net.pterodactylus.sone.core;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.mockito.hamcrest.MockitoHamcrest.argThat;
import net.pterodactylus.sone.core.Core.MarkPostKnown;
import net.pterodactylus.sone.core.Core.MarkReplyKnown;
+import net.pterodactylus.sone.core.event.PostRemovedEvent;
+import net.pterodactylus.sone.core.event.PostReplyRemovedEvent;
+import net.pterodactylus.sone.core.event.SoneRemovedEvent;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.Database;
+import net.pterodactylus.sone.freenet.wot.Identity;
+import net.pterodactylus.sone.freenet.wot.IdentityManager;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
+import net.pterodactylus.sone.freenet.wot.event.IdentityRemovedEvent;
+import net.pterodactylus.util.config.Configuration;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.eventbus.EventBus;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeDiagnosingMatcher;
import org.junit.Test;
+import org.mockito.InOrder;
/**
* Unit test for {@link Core} and its subclasses.
- *
- * @author David âBombeâ Roden
*/
public class CoreTest {
@@ -36,4 +54,108 @@ public class CoreTest {
verify(core).markReplyKnown(eq(postReply));
}
+ @Test
+ public void removingAnIdentitySendsRemovalEventsForAllSoneElements() {
+ // given
+ Configuration configuration = mock(Configuration.class);
+ FreenetInterface freenetInterface = mock(FreenetInterface.class);
+ IdentityManager identityManager = mock(IdentityManager.class);
+ SoneDownloader soneDownloader = mock(SoneDownloader.class);
+ ImageInserter imageInserter = mock(ImageInserter.class);
+ UpdateChecker updateChecker = mock(UpdateChecker.class);
+ WebOfTrustUpdater webOfTrustUpdater = mock(WebOfTrustUpdater.class);
+ EventBus eventBus = mock(EventBus.class);
+ Database database = mock(Database.class);
+ Core core = new Core(configuration, freenetInterface, identityManager, soneDownloader, imageInserter, updateChecker, webOfTrustUpdater, eventBus, database);
+ OwnIdentity ownIdentity = mock(OwnIdentity.class);
+ Identity identity = mock(Identity.class);
+ when(identity.getId()).thenReturn("sone-id");
+ Sone sone = mock(Sone.class);
+ when(database.getSone("sone-id")).thenReturn(sone);
+ PostReply postReply1 = mock(PostReply.class);
+ PostReply postReply2 = mock(PostReply.class);
+ when(sone.getReplies()).thenReturn(ImmutableSet.of(postReply1, postReply2));
+ Post post1 = mock(Post.class);
+ Post post2 = mock(Post.class);
+ when(sone.getPosts()).thenReturn(ImmutableList.of(post1, post2));
+
+ // when
+ core.identityRemoved(new IdentityRemovedEvent(ownIdentity, identity));
+
+ // then
+ InOrder inOrder = inOrder(eventBus, database);
+ inOrder.verify(eventBus).post(argThat(isPostReplyRemoved(postReply1)));
+ inOrder.verify(eventBus).post(argThat(isPostReplyRemoved(postReply2)));
+ inOrder.verify(eventBus).post(argThat(isPostRemoved(post1)));
+ inOrder.verify(eventBus).post(argThat(isPostRemoved(post2)));
+ inOrder.verify(eventBus).post(argThat(isSoneRemoved(sone)));
+ inOrder.verify(database).removeSone(sone);
+ }
+
+ private Matcher