🎨 Replace change detectors with Kotlin versions
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 23 Sep 2019 17:06:53 +0000 (19:06 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 23 Sep 2019 17:06:53 +0000 (19:06 +0200)
src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.java [deleted file]
src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.kt [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSender.java [deleted file]
src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSender.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeDetectorTest.kt

diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.java
deleted file mode 100644 (file)
index b2982e8..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Sone - IdentityChangeDetector.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 java.util.*;
-import java.util.Map.*;
-import java.util.function.*;
-import java.util.stream.*;
-
-import com.google.common.collect.*;
-
-/**
- * Detects changes between two lists of {@link Identity}s. The detector can find
- * added and removed identities, and for identities that exist in both list
- * their contexts and properties are checked for added, removed, or (in case of
- * properties) changed values.
- */
-public class IdentityChangeDetector {
-
-       private final Map<String, Identity> oldIdentities;
-       private IdentityProcessor onNewIdentity;
-       private IdentityProcessor onRemovedIdentity;
-       private IdentityProcessor onChangedIdentity;
-       private IdentityProcessor onUnchangedIdentity;
-
-       public IdentityChangeDetector(Collection<? extends Identity> oldIdentities) {
-               this.oldIdentities = convertToMap(oldIdentities);
-       }
-
-       public void onNewIdentity(IdentityProcessor onNewIdentity) {
-               this.onNewIdentity = onNewIdentity;
-       }
-
-       public void onRemovedIdentity(IdentityProcessor onRemovedIdentity) {
-               this.onRemovedIdentity = onRemovedIdentity;
-       }
-
-       public void onChangedIdentity(IdentityProcessor onChangedIdentity) {
-               this.onChangedIdentity = onChangedIdentity;
-       }
-
-       public void onUnchangedIdentity(IdentityProcessor onUnchangedIdentity) {
-               this.onUnchangedIdentity = onUnchangedIdentity;
-       }
-
-       public void detectChanges(final Collection<? extends Identity> newIdentities) {
-               notifyForRemovedIdentities(oldIdentities.values().stream().filter(notContainedIn(newIdentities)).collect(Collectors.toList()));
-               notifyForNewIdentities(newIdentities.stream().filter(notContainedIn(oldIdentities.values())).collect(Collectors.toList()));
-               notifyForChangedIdentities(newIdentities.stream().filter(containedIn(oldIdentities)).filter(hasChanged(oldIdentities)).collect(Collectors.toList()));
-               notifyForUnchangedIdentities(newIdentities.stream().filter(containedIn(oldIdentities)).filter(hasChanged(oldIdentities).negate()).collect(Collectors.toList()));
-       }
-
-       private void notifyForRemovedIdentities(Iterable<Identity> identities) {
-               notify(onRemovedIdentity, identities);
-       }
-
-       private void notifyForNewIdentities(Iterable<? extends Identity> newIdentities) {
-               notify(onNewIdentity, newIdentities);
-       }
-
-       private void notifyForChangedIdentities(Iterable<? extends Identity> identities) {
-               notify(onChangedIdentity, identities);
-       }
-
-       private void notifyForUnchangedIdentities(Iterable<? extends Identity> identities) {
-               notify(onUnchangedIdentity, identities);
-       }
-
-       private void notify(IdentityProcessor identityProcessor, Iterable<? extends Identity> identities) {
-               if (identityProcessor == null) {
-                       return;
-               }
-               for (Identity identity : identities) {
-                       identityProcessor.processIdentity(identity);
-               }
-       }
-
-       private static Predicate<Identity> hasChanged(final Map<String, Identity> oldIdentities) {
-               return identity -> (identity != null) && identityHasChanged(oldIdentities.get(identity.getId()), identity);
-       }
-
-       private static boolean identityHasChanged(Identity oldIdentity, Identity newIdentity) {
-               return identityHasNewContexts(oldIdentity, newIdentity)
-                               || identityHasRemovedContexts(oldIdentity, newIdentity)
-                               || identityHasNewProperties(oldIdentity, newIdentity)
-                               || identityHasRemovedProperties(oldIdentity, newIdentity)
-                               || identityHasChangedProperties(oldIdentity, newIdentity);
-       }
-
-       private static boolean identityHasNewContexts(Identity oldIdentity, Identity newIdentity) {
-               return newIdentity.getContexts().stream().anyMatch(notAContextOf(oldIdentity));
-       }
-
-       private static boolean identityHasRemovedContexts(Identity oldIdentity, Identity newIdentity) {
-               return oldIdentity.getContexts().stream().anyMatch(notAContextOf(newIdentity));
-       }
-
-       private static boolean identityHasNewProperties(Identity oldIdentity, Identity newIdentity) {
-               return newIdentity.getProperties().entrySet().stream().anyMatch(notAPropertyOf(oldIdentity));
-       }
-
-       private static boolean identityHasRemovedProperties(Identity oldIdentity, Identity newIdentity) {
-               return oldIdentity.getProperties().entrySet().stream().anyMatch(notAPropertyOf(newIdentity));
-       }
-
-       private static boolean identityHasChangedProperties(Identity oldIdentity, Identity newIdentity) {
-               return oldIdentity.getProperties().entrySet().stream().anyMatch(hasADifferentValueThanIn(newIdentity));
-       }
-
-       private static Predicate<Identity> containedIn(final Map<String, Identity> identities) {
-               return identity -> (identity != null) && identities.containsKey(identity.getId());
-       }
-
-       private static Predicate<String> notAContextOf(final Identity identity) {
-               return context -> (identity != null) && !identity.getContexts().contains(context);
-       }
-
-       private static Predicate<Identity> notContainedIn(final Collection<? extends Identity> newIdentities) {
-               return identity -> (identity != null) && !newIdentities.contains(identity);
-       }
-
-       private static Predicate<Entry<String, String>> notAPropertyOf(final Identity identity) {
-               return property -> (property != null) && !identity.getProperties().containsKey(property.getKey());
-       }
-
-       private static Predicate<Entry<String, String>> hasADifferentValueThanIn(final Identity newIdentity) {
-               return property -> (property != null) && !newIdentity.getProperty(property.getKey()).equals(property.getValue());
-       }
-
-       private static Map<String, Identity> convertToMap(Collection<? extends Identity> identities) {
-               ImmutableMap.Builder<String, Identity> mapBuilder = ImmutableMap.builder();
-               for (Identity identity : identities) {
-                       mapBuilder.put(identity.getId(), identity);
-               }
-               return mapBuilder.build();
-       }
-
-       public interface IdentityProcessor {
-
-               void processIdentity(Identity identity);
-
-       }
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.kt b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.kt
new file mode 100644 (file)
index 0000000..deb35b1
--- /dev/null
@@ -0,0 +1,68 @@
+/*
+ * Sone - IdentityChangeDetector.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
+
+/**
+ * Detects changes between two lists of [Identity]s. The detector can find
+ * added and removed identities, and for identities that exist in both list
+ * their contexts and properties are checked for added, removed, or (in case of
+ * properties) changed values.
+ */
+class IdentityChangeDetector(oldIdentities: Collection<Identity>) {
+
+       private val oldIdentities: Map<String, Identity> = oldIdentities.associateBy { it.id }
+       var onNewIdentity: IdentityProcessor? = null
+       var onRemovedIdentity: IdentityProcessor? = null
+       var onChangedIdentity: IdentityProcessor? = null
+       var onUnchangedIdentity: IdentityProcessor? = null
+
+       fun detectChanges(newIdentities: Collection<Identity>) {
+               onRemovedIdentity.notify(oldIdentities.values.filter { it !in newIdentities })
+               onNewIdentity.notify(newIdentities.filter { it !in oldIdentities.values })
+               onChangedIdentity.notify(newIdentities.filter { it.id in oldIdentities }.filter { identityHasChanged(oldIdentities[it.id]!!, it) })
+               onUnchangedIdentity.notify(newIdentities.filter { it.id in oldIdentities }.filterNot { identityHasChanged(oldIdentities[it.id]!!, it) })
+       }
+
+       private fun identityHasChanged(oldIdentity: Identity, newIdentity: Identity?) =
+                       identityHasNewContexts(oldIdentity, newIdentity!!)
+                                       || identityHasRemovedContexts(oldIdentity, newIdentity)
+                                       || identityHasNewProperties(oldIdentity, newIdentity)
+                                       || identityHasRemovedProperties(oldIdentity, newIdentity)
+                                       || identityHasChangedProperties(oldIdentity, newIdentity)
+
+       private fun identityHasNewContexts(oldIdentity: Identity, newIdentity: Identity) =
+                       newIdentity.contexts.any { it !in oldIdentity.contexts }
+
+       private fun identityHasRemovedContexts(oldIdentity: Identity, newIdentity: Identity) =
+                       oldIdentity.contexts.any { it !in newIdentity.contexts }
+
+       private fun identityHasNewProperties(oldIdentity: Identity, newIdentity: Identity) =
+                       newIdentity.properties.keys.any { it !in oldIdentity.properties }
+
+       private fun identityHasRemovedProperties(oldIdentity: Identity, newIdentity: Identity) =
+                       oldIdentity.properties.keys.any { it !in newIdentity.properties }
+
+       private fun identityHasChangedProperties(oldIdentity: Identity, newIdentity: Identity) =
+                       oldIdentity.properties.entries.any { newIdentity.properties[it.key] != it.value }
+
+}
+
+typealias IdentityProcessor = (Identity) -> Unit
+
+private fun IdentityProcessor?.notify(identities: Iterable<Identity>) =
+               this?.let { identities.forEach(this::invoke) }
diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSender.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSender.java
deleted file mode 100644 (file)
index fd57c38..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Sone - IdentityChangeEventSender.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 java.util.Collection;
-import java.util.Map;
-
-import net.pterodactylus.sone.freenet.wot.IdentityChangeDetector.IdentityProcessor;
-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;
-
-/**
- * Detects changes in {@link Identity}s trusted my multiple {@link
- * OwnIdentity}s.
- *
- * @see IdentityChangeDetector
- */
-public class IdentityChangeEventSender {
-
-       private final EventBus eventBus;
-       private final Map<OwnIdentity, Collection<Identity>> oldIdentities;
-
-       public IdentityChangeEventSender(EventBus eventBus, Map<OwnIdentity, Collection<Identity>> oldIdentities) {
-               this.eventBus = eventBus;
-               this.oldIdentities = oldIdentities;
-       }
-
-       public void detectChanges(Map<OwnIdentity, Collection<Identity>> identities) {
-               IdentityChangeDetector identityChangeDetector = new IdentityChangeDetector(oldIdentities.keySet());
-               identityChangeDetector.onNewIdentity(addNewOwnIdentityAndItsTrustedIdentities(identities));
-               identityChangeDetector.onRemovedIdentity(removeOwnIdentityAndItsTrustedIdentities(oldIdentities));
-               identityChangeDetector.onUnchangedIdentity(detectChangesInTrustedIdentities(identities, oldIdentities));
-               identityChangeDetector.detectChanges(identities.keySet());
-       }
-
-       private IdentityProcessor addNewOwnIdentityAndItsTrustedIdentities(final Map<OwnIdentity, Collection<Identity>> newIdentities) {
-               return new IdentityProcessor() {
-                       @Override
-                       public void processIdentity(Identity identity) {
-                               eventBus.post(new OwnIdentityAddedEvent((OwnIdentity) identity));
-                               for (Identity newIdentity : newIdentities.get((OwnIdentity) identity)) {
-                                       eventBus.post(new IdentityAddedEvent((OwnIdentity) identity, newIdentity));
-                               }
-                       }
-               };
-       }
-
-       private IdentityProcessor removeOwnIdentityAndItsTrustedIdentities(final Map<OwnIdentity, Collection<Identity>> oldIdentities) {
-               return new IdentityProcessor() {
-                       @Override
-                       public void processIdentity(Identity identity) {
-                               eventBus.post(new OwnIdentityRemovedEvent((OwnIdentity) identity));
-                               for (Identity removedIdentity : oldIdentities.get((OwnIdentity) identity)) {
-                                       eventBus.post(new IdentityRemovedEvent((OwnIdentity) identity, removedIdentity));
-                               }
-                       }
-               };
-       }
-
-       private IdentityProcessor detectChangesInTrustedIdentities(Map<OwnIdentity, Collection<Identity>> newIdentities, Map<OwnIdentity, Collection<Identity>> oldIdentities) {
-               return new DefaultIdentityProcessor(oldIdentities, newIdentities);
-       }
-
-       private class DefaultIdentityProcessor implements IdentityProcessor {
-
-               private final Map<OwnIdentity, Collection<Identity>> oldIdentities;
-               private final Map<OwnIdentity, Collection<Identity>> newIdentities;
-
-               public DefaultIdentityProcessor(Map<OwnIdentity, Collection<Identity>> oldIdentities, Map<OwnIdentity, Collection<Identity>> newIdentities) {
-                       this.oldIdentities = oldIdentities;
-                       this.newIdentities = newIdentities;
-               }
-
-               @Override
-               public void processIdentity(Identity ownIdentity) {
-                       IdentityChangeDetector identityChangeDetector = new IdentityChangeDetector(oldIdentities.get((OwnIdentity) ownIdentity));
-                       identityChangeDetector.onNewIdentity(notifyForAddedIdentities((OwnIdentity) ownIdentity));
-                       identityChangeDetector.onRemovedIdentity(notifyForRemovedIdentities((OwnIdentity) ownIdentity));
-                       identityChangeDetector.onChangedIdentity(notifyForChangedIdentities((OwnIdentity) ownIdentity));
-                       identityChangeDetector.detectChanges(newIdentities.get((OwnIdentity) ownIdentity));
-               }
-
-               private IdentityProcessor notifyForChangedIdentities(final OwnIdentity ownIdentity) {
-                       return new IdentityProcessor() {
-                               @Override
-                               public void processIdentity(Identity identity) {
-                                       eventBus.post(new IdentityUpdatedEvent(ownIdentity, identity));
-                               }
-                       };
-               }
-
-               private IdentityProcessor notifyForRemovedIdentities(final OwnIdentity ownIdentity) {
-                       return new IdentityProcessor() {
-                               @Override
-                               public void processIdentity(Identity identity) {
-                                       eventBus.post(new IdentityRemovedEvent(ownIdentity, identity));
-                               }
-                       };
-               }
-
-               private IdentityProcessor notifyForAddedIdentities(final OwnIdentity ownIdentity) {
-                       return new IdentityProcessor() {
-                               @Override
-                               public void processIdentity(Identity identity) {
-                                       eventBus.post(new IdentityAddedEvent(ownIdentity, identity));
-                               }
-                       };
-               }
-
-       }
-
-}
diff --git a/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSender.kt b/src/main/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSender.kt
new file mode 100644 (file)
index 0000000..5ffffa3
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Sone - IdentityChangeEventSender.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.event.*
+
+/**
+ * Detects changes in [Identity]s trusted by multiple [OwnIdentity]s.
+ *
+ * @see IdentityChangeDetector
+ */
+class IdentityChangeEventSender(private val eventBus: EventBus, private val oldIdentities: Map<OwnIdentity, Collection<Identity>>) {
+
+       fun detectChanges(identities: Map<OwnIdentity, Collection<Identity>>) {
+               val identityChangeDetector = IdentityChangeDetector(oldIdentities.keys)
+               identityChangeDetector.onNewIdentity = addNewOwnIdentityAndItsTrustedIdentities(identities)
+               identityChangeDetector.onRemovedIdentity = removeOwnIdentityAndItsTrustedIdentities(oldIdentities)
+               identityChangeDetector.onUnchangedIdentity = detectChangesInTrustedIdentities(identities, oldIdentities)
+               identityChangeDetector.detectChanges(identities.keys)
+       }
+
+       private fun addNewOwnIdentityAndItsTrustedIdentities(newIdentities: Map<OwnIdentity, Collection<Identity>>) =
+                       { identity: Identity ->
+                               eventBus.post(OwnIdentityAddedEvent(identity as OwnIdentity))
+                               newIdentities[identity]
+                                               ?.map { IdentityAddedEvent(identity, it) }
+                                               ?.forEach(eventBus::post) ?: Unit
+                       }
+
+       private fun removeOwnIdentityAndItsTrustedIdentities(oldIdentities: Map<OwnIdentity, Collection<Identity>>) =
+                       { identity: Identity ->
+                               eventBus.post(OwnIdentityRemovedEvent(identity as OwnIdentity))
+                               oldIdentities[identity]
+                                               ?.map { IdentityRemovedEvent(identity, it) }
+                                               ?.forEach(eventBus::post) ?: Unit
+                       }
+
+       private fun detectChangesInTrustedIdentities(newIdentities: Map<OwnIdentity, Collection<Identity>>, oldIdentities: Map<OwnIdentity, Collection<Identity>>) =
+                       { ownIdentity: Identity ->
+                               val identityChangeDetector = IdentityChangeDetector(oldIdentities[ownIdentity as OwnIdentity]!!)
+                               identityChangeDetector.onNewIdentity = { eventBus.post(IdentityAddedEvent(ownIdentity, it)) }
+                               identityChangeDetector.onRemovedIdentity = { eventBus.post(IdentityRemovedEvent(ownIdentity, it)) }
+                               identityChangeDetector.onChangedIdentity = { eventBus.post(IdentityUpdatedEvent(ownIdentity, it)) }
+                               identityChangeDetector.detectChanges(newIdentities[ownIdentity]!!)
+                       }
+
+}
index aa1b7f0..ab9570d 100644 (file)
 
 package net.pterodactylus.sone.freenet.wot
 
-import net.pterodactylus.sone.freenet.wot.Identities.createIdentity
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers.containsInAnyOrder
-import org.hamcrest.Matchers.empty
-
-import org.junit.Before
-import org.junit.Test
+import net.pterodactylus.sone.freenet.wot.Identities.*
+import org.hamcrest.MatcherAssert.*
+import org.hamcrest.Matchers.*
+import org.junit.*
 
 /**
  * Unit test for [IdentityChangeDetector].
@@ -38,37 +35,37 @@ class IdentityChangeDetectorTest {
 
        @Before
        fun setup() {
-               identityChangeDetector.onNewIdentity { identity -> newIdentities.add(identity) }
-               identityChangeDetector.onRemovedIdentity { identity -> removedIdentities.add(identity) }
-               identityChangeDetector.onChangedIdentity { identity -> changedIdentities.add(identity) }
-               identityChangeDetector.onUnchangedIdentity { identity -> unchangedIdentities.add(identity) }
+               identityChangeDetector.onNewIdentity { identity -> newIdentities.add(identity) }
+               identityChangeDetector.onRemovedIdentity { identity -> removedIdentities.add(identity) }
+               identityChangeDetector.onChangedIdentity { identity -> changedIdentities.add(identity) }
+               identityChangeDetector.onUnchangedIdentity { identity -> unchangedIdentities.add(identity) }
        }
 
        @Test
        fun `no differences are detected when sending the old identities again`() {
                identityChangeDetector.detectChanges(createOldIdentities())
-               assertThat<Collection<Identity>>(newIdentities, empty())
-               assertThat<Collection<Identity>>(removedIdentities, empty())
-               assertThat<Collection<Identity>>(changedIdentities, empty())
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2(), createIdentity3()))
+               assertThat(newIdentities, empty())
+               assertThat(removedIdentities, empty())
+               assertThat(changedIdentities, empty())
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2(), createIdentity3()))
        }
 
        @Test
        fun `detect that an identity was removed`() {
                identityChangeDetector.detectChanges(listOf(createIdentity1(), createIdentity3()))
-               assertThat<Collection<Identity>>(newIdentities, empty())
-               assertThat<Collection<Identity>>(removedIdentities, containsInAnyOrder(createIdentity2()))
-               assertThat<Collection<Identity>>(changedIdentities, empty())
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity3()))
+               assertThat(newIdentities, empty())
+               assertThat(removedIdentities, containsInAnyOrder(createIdentity2()))
+               assertThat(changedIdentities, empty())
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity3()))
        }
 
        @Test
        fun `detect that an identity was added`() {
                identityChangeDetector.detectChanges(listOf(createIdentity1(), createIdentity2(), createIdentity3(), createIdentity4()))
-               assertThat<Collection<Identity>>(newIdentities, containsInAnyOrder(createIdentity4()))
-               assertThat<Collection<Identity>>(removedIdentities, empty())
-               assertThat<Collection<Identity>>(changedIdentities, empty())
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2(), createIdentity3()))
+               assertThat(newIdentities, containsInAnyOrder(createIdentity4()))
+               assertThat(removedIdentities, empty())
+               assertThat(changedIdentities, empty())
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2(), createIdentity3()))
        }
 
        @Test
@@ -76,10 +73,10 @@ class IdentityChangeDetectorTest {
                val identity2 = createIdentity2()
                identity2.removeContext("Context C")
                identityChangeDetector.detectChanges(listOf(createIdentity1(), identity2, createIdentity3()))
-               assertThat<Collection<Identity>>(newIdentities, empty())
-               assertThat<Collection<Identity>>(removedIdentities, empty())
-               assertThat<Collection<Identity>>(changedIdentities, containsInAnyOrder(identity2))
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity3()))
+               assertThat(newIdentities, empty())
+               assertThat(removedIdentities, empty())
+               assertThat(changedIdentities, containsInAnyOrder(identity2))
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity3()))
        }
 
        @Test
@@ -87,10 +84,10 @@ class IdentityChangeDetectorTest {
                val identity2 = createIdentity2()
                identity2.addContext("Context C1")
                identityChangeDetector.detectChanges(listOf(createIdentity1(), identity2, createIdentity3()))
-               assertThat<Collection<Identity>>(newIdentities, empty())
-               assertThat<Collection<Identity>>(removedIdentities, empty())
-               assertThat<Collection<Identity>>(changedIdentities, containsInAnyOrder(identity2))
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity3()))
+               assertThat(newIdentities, empty())
+               assertThat(removedIdentities, empty())
+               assertThat(changedIdentities, containsInAnyOrder(identity2))
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity3()))
        }
 
        @Test
@@ -98,10 +95,10 @@ class IdentityChangeDetectorTest {
                val identity1 = createIdentity1()
                identity1.removeProperty("Key A")
                identityChangeDetector.detectChanges(listOf(identity1, createIdentity2(), createIdentity3()))
-               assertThat<Collection<Identity>>(newIdentities, empty())
-               assertThat<Collection<Identity>>(removedIdentities, empty())
-               assertThat<Collection<Identity>>(changedIdentities, containsInAnyOrder(identity1))
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity2(), createIdentity3()))
+               assertThat(newIdentities, empty())
+               assertThat(removedIdentities, empty())
+               assertThat(changedIdentities, containsInAnyOrder(identity1))
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity2(), createIdentity3()))
        }
 
        @Test
@@ -109,10 +106,10 @@ class IdentityChangeDetectorTest {
                val identity3 = createIdentity3()
                identity3.setProperty("Key A", "Value A")
                identityChangeDetector.detectChanges(listOf(createIdentity1(), createIdentity2(), identity3))
-               assertThat<Collection<Identity>>(newIdentities, empty())
-               assertThat<Collection<Identity>>(removedIdentities, empty())
-               assertThat<Collection<Identity>>(changedIdentities, containsInAnyOrder(identity3))
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2()))
+               assertThat(newIdentities, empty())
+               assertThat(removedIdentities, empty())
+               assertThat(changedIdentities, containsInAnyOrder(identity3))
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2()))
        }
 
        @Test
@@ -120,44 +117,39 @@ class IdentityChangeDetectorTest {
                val identity3 = createIdentity3()
                identity3.setProperty("Key E", "Value F")
                identityChangeDetector.detectChanges(listOf(createIdentity1(), createIdentity2(), identity3))
-               assertThat<Collection<Identity>>(newIdentities, empty())
-               assertThat<Collection<Identity>>(removedIdentities, empty())
-               assertThat<Collection<Identity>>(changedIdentities, containsInAnyOrder(identity3))
-               assertThat<Collection<Identity>>(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2()))
+               assertThat(newIdentities, empty())
+               assertThat(removedIdentities, empty())
+               assertThat(changedIdentities, containsInAnyOrder(identity3))
+               assertThat(unchangedIdentities, containsInAnyOrder(createIdentity1(), createIdentity2()))
        }
 
        @Test
        fun `no removed identities are detected without an identity processor`() {
-               identityChangeDetector.onRemovedIdentity(null)
+               identityChangeDetector.onRemovedIdentity = null
                identityChangeDetector.detectChanges(listOf(createIdentity1(), createIdentity3()))
                assertThat(removedIdentities, empty())
        }
 
        @Test
        fun `no added identities are detected without an identity processor`() {
-               identityChangeDetector.onNewIdentity(null)
+               identityChangeDetector.onNewIdentity = null
                identityChangeDetector.detectChanges(listOf(createIdentity1(), createIdentity2(), createIdentity3(), createIdentity4()))
                assertThat(newIdentities, empty())
        }
 
-       private fun createOldIdentities(): Collection<Identity> {
-               return listOf(createIdentity1(), createIdentity2(), createIdentity3())
-       }
+       private fun createOldIdentities() =
+                       listOf(createIdentity1(), createIdentity2(), createIdentity3())
 
-       private fun createIdentity1(): Identity {
-               return createIdentity("Test1", listOf("Context A", "Context B"), mapOf("Key A" to "Value A", "Key B" to "Value B"))
-       }
+       private fun createIdentity1() =
+                       createIdentity("Test1", listOf("Context A", "Context B"), mapOf("Key A" to "Value A", "Key B" to "Value B"))
 
-       private fun createIdentity2(): Identity {
-               return createIdentity("Test2", listOf("Context C", "Context D"), mapOf("Key C" to "Value C", "Key D" to "Value D"))
-       }
+       private fun createIdentity2() =
+                       createIdentity("Test2", listOf("Context C", "Context D"), mapOf("Key C" to "Value C", "Key D" to "Value D"))
 
-       private fun createIdentity3(): Identity {
-               return createIdentity("Test3", listOf("Context E", "Context F"), mapOf("Key E" to "Value E", "Key F" to "Value F"))
-       }
+       private fun createIdentity3() =
+                       createIdentity("Test3", listOf("Context E", "Context F"), mapOf("Key E" to "Value E", "Key F" to "Value F"))
 
-       private fun createIdentity4(): Identity {
-               return createIdentity("Test4", listOf("Context G", "Context H"), mapOf("Key G" to "Value G", "Key H" to "Value H"))
-       }
+       private fun createIdentity4() =
+                       createIdentity("Test4", listOf("Context G", "Context H"), mapOf("Key G" to "Value G", "Key H" to "Value H"))
 
 }