🎨 Replace IdentityChangeEventSenderTest with Kotlin version
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 20 Sep 2019 05:39:00 +0000 (07:39 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 20 Sep 2019 05:39:00 +0000 (07:39 +0200)
src/test/java/net/pterodactylus/sone/freenet/wot/Identities.java
src/test/java/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.java [deleted file]
src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.kt [new file with mode: 0644]

index 7ed2b59..089cc5a 100644 (file)
@@ -19,18 +19,21 @@ package net.pterodactylus.sone.freenet.wot;
 
 import java.util.Collection;
 import java.util.Map;
+import javax.annotation.*;
 
 /**
  * Creates {@link Identity}s and {@link OwnIdentity}s.
  */
 public class Identities {
 
+       @Nonnull
        public static OwnIdentity createOwnIdentity(String id, Collection<String> contexts, Map<String, String> properties) {
                DefaultOwnIdentity ownIdentity = new DefaultOwnIdentity(id, "Nickname" + id, "Request" + id, "Insert" + id);
                setContextsAndPropertiesOnIdentity(ownIdentity, contexts, properties);
                return ownIdentity;
        }
 
+       @Nonnull
        public static Identity createIdentity(String id, Collection<String> contexts, Map<String, String> properties) {
                DefaultIdentity identity = new DefaultIdentity(id, "Nickname" + id, "Request" + id);
                setContextsAndPropertiesOnIdentity(identity, contexts, properties);
diff --git a/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.java b/src/test/java/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.java
deleted file mode 100644 (file)
index ff442a4..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Sone - IdentityChangeEventSenderTest.java - Copyright Â© 2013–2019 David Roden
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.freenet.wot;
-
-import static com.google.common.collect.ImmutableMap.of;
-import static java.util.Arrays.asList;
-import static net.pterodactylus.sone.freenet.wot.Identities.createIdentity;
-import static net.pterodactylus.sone.freenet.wot.Identities.createOwnIdentity;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import net.pterodactylus.sone.freenet.wot.event.IdentityAddedEvent;
-import net.pterodactylus.sone.freenet.wot.event.IdentityRemovedEvent;
-import net.pterodactylus.sone.freenet.wot.event.IdentityUpdatedEvent;
-import net.pterodactylus.sone.freenet.wot.event.OwnIdentityAddedEvent;
-import net.pterodactylus.sone.freenet.wot.event.OwnIdentityRemovedEvent;
-
-import com.google.common.eventbus.EventBus;
-import org.junit.Test;
-
-/**
- * Unit test for {@link IdentityChangeEventSender}.
- */
-public class IdentityChangeEventSenderTest {
-
-       private final EventBus eventBus = mock(EventBus.class);
-       private final List<OwnIdentity> ownIdentities = asList(
-                       createOwnIdentity("O1", asList("Test"), of("KeyA", "ValueA")),
-                       createOwnIdentity("O2", asList("Test2"), of("KeyB", "ValueB")),
-                       createOwnIdentity("O3", asList("Test3"), of("KeyC", "ValueC"))
-       );
-       private final List<Identity> identities = asList(
-                       createIdentity("I1", Collections.<String>emptyList(), Collections.<String, String>emptyMap()),
-                       createIdentity("I2", Collections.<String>emptyList(), Collections.<String, String>emptyMap()),
-                       createIdentity("I3", Collections.<String>emptyList(), Collections.<String, String>emptyMap()),
-                       createIdentity("I2", asList("Test"), Collections.<String, String>emptyMap())
-       );
-       private final IdentityChangeEventSender identityChangeEventSender = new IdentityChangeEventSender(eventBus, createOldIdentities());
-
-       @Test
-       public void addingAnOwnIdentityIsDetectedAndReportedCorrectly() {
-               Map<OwnIdentity, Collection<Identity>> newIdentities = createNewIdentities();
-               identityChangeEventSender.detectChanges(newIdentities);
-               verify(eventBus).post(eq(new OwnIdentityRemovedEvent(ownIdentities.get(0))));
-               verify(eventBus).post(eq(new IdentityRemovedEvent(ownIdentities.get(0), identities.get(0))));
-               verify(eventBus).post(eq(new IdentityRemovedEvent(ownIdentities.get(0), identities.get(1))));
-               verify(eventBus).post(eq(new OwnIdentityAddedEvent(ownIdentities.get(2))));
-               verify(eventBus).post(eq(new IdentityAddedEvent(ownIdentities.get(2), identities.get(1))));
-               verify(eventBus).post(eq(new IdentityAddedEvent(ownIdentities.get(2), identities.get(2))));
-               verify(eventBus).post(eq(new IdentityRemovedEvent(ownIdentities.get(1), identities.get(0))));
-               verify(eventBus).post(eq(new IdentityAddedEvent(ownIdentities.get(1), identities.get(2))));
-               verify(eventBus).post(eq(new IdentityUpdatedEvent(ownIdentities.get(1), identities.get(1))));
-       }
-
-       private Map<OwnIdentity, Collection<Identity>> createNewIdentities() {
-               Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<>();
-               oldIdentities.put(ownIdentities.get(1), asList(identities.get(3), identities.get(2)));
-               oldIdentities.put(ownIdentities.get(2), asList(identities.get(1), identities.get(2)));
-               return oldIdentities;
-       }
-
-       private Map<OwnIdentity, Collection<Identity>> createOldIdentities() {
-               Map<OwnIdentity, Collection<Identity>> oldIdentities = new HashMap<>();
-               oldIdentities.put(ownIdentities.get(0), asList(identities.get(0), identities.get(1)));
-               oldIdentities.put(ownIdentities.get(1), asList(identities.get(0), identities.get(1)));
-               return oldIdentities;
-       }
-
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.kt
new file mode 100644 (file)
index 0000000..69fc9d4
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Sone - IdentityChangeEventSenderTest.java - Copyright Â© 2013–2019 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.freenet.wot
+
+import com.google.common.eventbus.*
+import net.pterodactylus.sone.freenet.wot.Identities.*
+import net.pterodactylus.sone.freenet.wot.event.*
+import net.pterodactylus.sone.test.*
+import org.junit.*
+import org.mockito.ArgumentMatchers.eq
+import org.mockito.Mockito.verify
+
+/**
+ * Unit test for [IdentityChangeEventSender].
+ */
+class IdentityChangeEventSenderTest {
+
+       private val eventBus = mock<EventBus>()
+       private val ownIdentities = listOf(
+                       createOwnIdentity("O1", listOf("Test"), mapOf("KeyA" to "ValueA")),
+                       createOwnIdentity("O2", listOf("Test2"), mapOf("KeyB" to "ValueB")),
+                       createOwnIdentity("O3", listOf("Test3"), mapOf("KeyC" to "ValueC"))
+       )
+       private val identities = listOf(
+                       createIdentity("I1", listOf(), mapOf()),
+                       createIdentity("I2", listOf(), mapOf()),
+                       createIdentity("I3", listOf(), mapOf()),
+                       createIdentity("I2", listOf("Test"), mapOf())
+       )
+       private val identityChangeEventSender = IdentityChangeEventSender(eventBus, createOldIdentities())
+
+       @Test
+       fun addingAnOwnIdentityIsDetectedAndReportedCorrectly() {
+               val newIdentities = createNewIdentities()
+               identityChangeEventSender.detectChanges(newIdentities)
+               verify(eventBus).post(eq(OwnIdentityRemovedEvent(ownIdentities[0])))
+               verify(eventBus).post(eq(IdentityRemovedEvent(ownIdentities[0], identities[0])))
+               verify(eventBus).post(eq(IdentityRemovedEvent(ownIdentities[0], identities[1])))
+               verify(eventBus).post(eq(OwnIdentityAddedEvent(ownIdentities[2])))
+               verify(eventBus).post(eq(IdentityAddedEvent(ownIdentities[2], identities[1])))
+               verify(eventBus).post(eq(IdentityAddedEvent(ownIdentities[2], identities[2])))
+               verify(eventBus).post(eq(IdentityRemovedEvent(ownIdentities[1], identities[0])))
+               verify(eventBus).post(eq(IdentityAddedEvent(ownIdentities[1], identities[2])))
+               verify(eventBus).post(eq(IdentityUpdatedEvent(ownIdentities[1], identities[1])))
+       }
+
+       private fun createNewIdentities() = mapOf(
+                       ownIdentities[1] to listOf(identities[3], identities[2]),
+                       ownIdentities[2] to listOf(identities[1], identities[2])
+       )
+
+       private fun createOldIdentities() = mapOf(
+                       ownIdentities[0] to listOf(identities[0], identities[1]),
+                       ownIdentities[1] to listOf(identities[0], identities[1])
+       )
+
+}