From 6a5b585e731597b33beed8f58a0e79b9f0c37f96 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 9 Oct 2019 20:51:01 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=8E=A8=20Replace=20Identities=20helper=20w?= =?utf8?q?ith=20Kotlin=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/sone/freenet/wot/Identities.java | 48 ---------------------- .../pterodactylus/sone/freenet/wot/Identities.kt | 35 ++++++++++++++++ .../sone/freenet/wot/IdentityChangeDetectorTest.kt | 9 ++-- .../freenet/wot/IdentityChangeEventSenderTest.kt | 15 ++++--- 4 files changed, 46 insertions(+), 61 deletions(-) delete mode 100644 src/test/java/net/pterodactylus/sone/freenet/wot/Identities.java create mode 100644 src/test/kotlin/net/pterodactylus/sone/freenet/wot/Identities.kt diff --git a/src/test/java/net/pterodactylus/sone/freenet/wot/Identities.java b/src/test/java/net/pterodactylus/sone/freenet/wot/Identities.java deleted file mode 100644 index 089cc5a..0000000 --- a/src/test/java/net/pterodactylus/sone/freenet/wot/Identities.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Sone - Identities.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 . - */ - -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 contexts, Map 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 contexts, Map properties) { - DefaultIdentity identity = new DefaultIdentity(id, "Nickname" + id, "Request" + id); - setContextsAndPropertiesOnIdentity(identity, contexts, properties); - return identity; - } - - private static void setContextsAndPropertiesOnIdentity(Identity identity, Collection contexts, Map properties) { - identity.setContexts(contexts); - identity.setProperties(properties); - } - -} diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/Identities.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/Identities.kt new file mode 100644 index 0000000..57ab8c5 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/Identities.kt @@ -0,0 +1,35 @@ +/* + * Sone - Identities.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 . + */ + +package net.pterodactylus.sone.freenet.wot + +fun createOwnIdentity(id: String, contexts: Collection, vararg properties: Pair): OwnIdentity { + val ownIdentity = DefaultOwnIdentity(id, "Nickname$id", "Request$id", "Insert$id") + setContextsAndPropertiesOnIdentity(ownIdentity, contexts, mapOf(*properties)) + return ownIdentity +} + +fun createIdentity(id: String, contexts: Collection, vararg properties: Pair): Identity { + val identity = DefaultIdentity(id, "Nickname$id", "Request$id") + setContextsAndPropertiesOnIdentity(identity, contexts, mapOf(*properties)) + return identity +} + +private fun setContextsAndPropertiesOnIdentity(identity: Identity, contexts: Collection, properties: Map) { + identity.setContexts(contexts) + identity.properties = properties +} diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeDetectorTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeDetectorTest.kt index ab9570d..aee99b7 100644 --- a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeDetectorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeDetectorTest.kt @@ -17,7 +17,6 @@ package net.pterodactylus.sone.freenet.wot -import net.pterodactylus.sone.freenet.wot.Identities.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* import org.junit.* @@ -141,15 +140,15 @@ class IdentityChangeDetectorTest { listOf(createIdentity1(), createIdentity2(), createIdentity3()) private fun createIdentity1() = - createIdentity("Test1", listOf("Context A", "Context B"), mapOf("Key A" to "Value A", "Key B" to "Value B")) + createIdentity("Test1", listOf("Context A", "Context B"), "Key A" to "Value A", "Key B" to "Value B") private fun createIdentity2() = - createIdentity("Test2", listOf("Context C", "Context D"), mapOf("Key C" to "Value C", "Key D" to "Value D")) + createIdentity("Test2", listOf("Context C", "Context D"), "Key C" to "Value C", "Key D" to "Value D") private fun createIdentity3() = - createIdentity("Test3", listOf("Context E", "Context F"), mapOf("Key E" to "Value E", "Key F" to "Value F")) + createIdentity("Test3", listOf("Context E", "Context F"), "Key E" to "Value E", "Key F" to "Value F") private fun createIdentity4() = - createIdentity("Test4", listOf("Context G", "Context H"), mapOf("Key G" to "Value G", "Key H" to "Value H")) + createIdentity("Test4", listOf("Context G", "Context H"), "Key G" to "Value G", "Key H" to "Value H") } diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.kt index 69fc9d4..5a4e853 100644 --- a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/IdentityChangeEventSenderTest.kt @@ -18,7 +18,6 @@ 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.* @@ -32,15 +31,15 @@ class IdentityChangeEventSenderTest { private val eventBus = mock() 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")) + createOwnIdentity("O1", listOf("Test"), "KeyA" to "ValueA"), + createOwnIdentity("O2", listOf("Test2"), "KeyB" to "ValueB"), + createOwnIdentity("O3", listOf("Test3"), "KeyC" to "ValueC") ) private val identities = listOf( - createIdentity("I1", listOf(), mapOf()), - createIdentity("I2", listOf(), mapOf()), - createIdentity("I3", listOf(), mapOf()), - createIdentity("I2", listOf("Test"), mapOf()) + createIdentity("I1", listOf()), + createIdentity("I2", listOf()), + createIdentity("I3", listOf()), + createIdentity("I2", listOf("Test")) ) private val identityChangeEventSender = IdentityChangeEventSender(eventBus, createOldIdentities()) -- 2.7.4