🐛 Make an identity’s nickname optional
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 3 Nov 2019 00:57:35 +0000 (01:57 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 3 Nov 2019 00:57:35 +0000 (01:57 +0100)
src/main/kotlin/net/pterodactylus/sone/freenet/wot/DefaultIdentity.kt
src/test/kotlin/net/pterodactylus/sone/freenet/wot/PluginWebOfTrustConnectorTest.kt
src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt

index 3398e7f..fe84584 100644 (file)
@@ -22,7 +22,7 @@ import java.util.Collections.*
 /**
  * A Web of Trust identity.
  */
-open class DefaultIdentity(private val id: String, private val nickname: String, private val requestUri: String) : Identity {
+open class DefaultIdentity(private val id: String, private val nickname: String?, private val requestUri: String) : Identity {
 
        private val contexts = mutableSetOf<String>().synchronized()
        private val properties = mutableMapOf<String, String>().synchronized()
index 5db7fe3..84acd65 100644 (file)
@@ -109,6 +109,20 @@ class PluginWebOfTrustConnectorTest {
        }
 
        @Test
+       fun `trusted identity without nickname is returned correctly`() {
+               val trustedIdentities = createPluginConnector("GetIdentitiesByScore") {
+                       put("Identity0", "id0")
+                       put("RequestURI0", "request-uri0")
+               }.connect { loadTrustedIdentities(ownIdentity) }
+               assertThat(trustedIdentities, contains(
+                               allOf(
+                                               isIdentity("id0", null, "request-uri0", empty<String>(), isEmptyMap()),
+                                               isTrusted(ownIdentity, isTrust(null, null, null))
+                               )
+               ))
+       }
+
+       @Test
        fun `trusted identity with contexts is returned correctly`() {
                val trustedIdentities = createPluginConnector("GetIdentitiesByScore") {
                        put("Identity0", "id0")
index e7588db..7fc9428 100644 (file)
@@ -58,7 +58,7 @@ fun isTrusted(ownIdentity: OwnIdentity, trust: Matcher<Trust>) = object : TypeSa
        }
 }
 
-fun isIdentity(id: String, nickname: String, requestUri: String, contexts: Matcher<out Iterable<String>>, properties: Matcher<out Map<out String, String>>) =
+fun isIdentity(id: String, nickname: String?, requestUri: String, contexts: Matcher<out Iterable<String>>, properties: Matcher<out Map<out String, String>>) =
                AttributeMatcher<Identity>("identity")
                                .addAttribute("id", id, Identity::getId)
                                .addAttribute("nickname", nickname, Identity::getNickname)