From c3e470d2626bcbd932d4b01ce3f6c6b17ce184fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 1 Nov 2019 19:34:16 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20tests=20for=20WOTC.getTrust?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../sone/freenet/wot/WebOfTrustConnector.java | 4 ++ .../sone/freenet/wot/WebOfTrustConnectorTest.kt | 53 ++++++++++++++++++++++ 2 files changed, 57 insertions(+) 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) = -- 2.7.4