+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-
-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);
- return identity;
- }
-
- private static void setContextsAndPropertiesOnIdentity(Identity identity, Collection<String> contexts, Map<String, String> properties) {
- identity.setContexts(contexts);
- identity.setProperties(properties);
- }
-
-}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.freenet.wot
+
+fun createOwnIdentity(id: String, contexts: Collection<String>, vararg properties: Pair<String, String>): OwnIdentity {
+ val ownIdentity = DefaultOwnIdentity(id, "Nickname$id", "Request$id", "Insert$id")
+ setContextsAndPropertiesOnIdentity(ownIdentity, contexts, mapOf(*properties))
+ return ownIdentity
+}
+
+fun createIdentity(id: String, contexts: Collection<String>, vararg properties: Pair<String, String>): Identity {
+ val identity = DefaultIdentity(id, "Nickname$id", "Request$id")
+ setContextsAndPropertiesOnIdentity(identity, contexts, mapOf(*properties))
+ return identity
+}
+
+private fun setContextsAndPropertiesOnIdentity(identity: Identity, contexts: Collection<String>, properties: Map<String, String>) {
+ identity.setContexts(contexts)
+ identity.properties = properties
+}
package net.pterodactylus.sone.freenet.wot
-import net.pterodactylus.sone.freenet.wot.Identities.*
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.junit.*
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")
}
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.*
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"))
+ 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())