From: David ‘Bombe’ Roden Date: Fri, 1 Nov 2019 18:34:16 +0000 (+0100) Subject: ✅ Add tests for WOTC.getTrust X-Git-Tag: v81^2~82 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=c3e470d2626bcbd932d4b01ce3f6c6b17ce184fd;p=Sone.git ✅ Add tests for WOTC.getTrust --- diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java index cd1b7fb..2bd3d48 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java @@ -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. */ diff --git a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/WebOfTrustConnectorTest.kt b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/WebOfTrustConnectorTest.kt index f7542b5..340d9ca 100644 --- a/src/test/kotlin/net/pterodactylus/sone/freenet/wot/WebOfTrustConnectorTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/freenet/wot/WebOfTrustConnectorTest.kt @@ -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 PluginConnector.connect(block: WebOfTrustConnector.() -> R) =