✅ Add tests for WOTC.getTrust
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Nov 2019 18:34:16 +0000 (19:34 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 1 Nov 2019 18:34:16 +0000 (19:34 +0100)
src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java
src/test/kotlin/net/pterodactylus/sone/freenet/wot/WebOfTrustConnectorTest.kt

index cd1b7fb..2bd3d48 100644 (file)
@@ -233,6 +233,10 @@ public class WebOfTrustConnector {
                }
                try {
                        implicit = Integer.valueOf(score);
+               } catch (NumberFormatException nfe1) {
+                       /* ignore. */
+               }
+               try {
                        distance = Integer.valueOf(rank);
                } catch (NumberFormatException nfe1) {
                        /* ignore. */
index f7542b5..340d9ca 100644 (file)
@@ -17,6 +17,7 @@ import kotlin.test.*
 class WebOfTrustConnectorTest {
 
        private val ownIdentity = DefaultOwnIdentity("id", "nickname", "requestUri", "insertUri")
+       private val identity = DefaultIdentity("id-a", "alpha", "url://alpha")
 
        @Test
        fun `wot plugin can be pinged`() {
@@ -209,6 +210,58 @@ class WebOfTrustConnectorTest {
                                .connect { removeProperty(ownIdentity, "TestProperty") }
        }
 
+       @Test
+       fun `getting trust sends correct own identity id`() {
+               createPluginConnector("GetIdentity", hasField("Truster", equalTo(ownIdentity.id)))
+                               .connect { getTrust(ownIdentity, identity) }
+       }
+
+       @Test
+       fun `getting trust sends correct identity id`() {
+               createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id)))
+                               .connect { getTrust(ownIdentity, identity) }
+       }
+
+       @Test
+       fun `getting trust returns correct trust values`() {
+               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
+                       put("Trust", "12")
+                       put("Score", "34")
+                       put("Rank", "56")
+               }.connect { getTrust(ownIdentity, identity) }
+               assertThat(trust, isTrust(12, 34, 56))
+       }
+
+       @Test
+       fun `getting trust reads incorrect numbers for trust as null`() {
+               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
+                       put("Trust", "incorrect")
+                       put("Score", "34")
+                       put("Rank", "56")
+               }.connect { getTrust(ownIdentity, identity) }
+               assertThat(trust, isTrust(null, 34, 56))
+       }
+
+       @Test
+       fun `getting trust reads incorrect numbers for score as null`() {
+               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
+                       put("Trust", "12")
+                       put("Score", "incorrect")
+                       put("Rank", "56")
+               }.connect { getTrust(ownIdentity, identity) }
+               assertThat(trust, isTrust(12, null, 56))
+       }
+
+       @Test
+       fun `getting trust reads incorrect numbers for rank as null`() {
+               val trust = createPluginConnector("GetIdentity", hasField("Identity", equalTo(identity.id))) {
+                       put("Trust", "12")
+                       put("Score", "34")
+                       put("Rank", "incorrect")
+               }.connect { getTrust(ownIdentity, identity) }
+               assertThat(trust, isTrust(12, 34, null))
+       }
+
 }
 
 private fun <R> PluginConnector.connect(block: WebOfTrustConnector.() -> R) =