From e7191fd598664d9d231501ed9cafd26b1c1a3e73 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 8 Jan 2025 08:38:36 +0100 Subject: [PATCH] =?utf8?q?=E2=9C=8F=EF=B8=8F=20Fix=20name=20of=20getOwnIde?= =?utf8?q?ntities()=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/fcp/plugin/WebOfTrustPlugin.java | 16 ++++++++++++ .../fcp/plugin/WebOfTrustPluginTest.java | 30 +++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java b/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java index cc47ccd..7ec12a3 100644 --- a/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java +++ b/src/main/java/net/pterodactylus/fcp/plugin/WebOfTrustPlugin.java @@ -121,8 +121,24 @@ public class WebOfTrustPlugin { * if an I/O error occurs * @throws FcpException * if an FCP error occurs + * @deprecated Use {@link #getOwnIdentities()} instead */ + @Deprecated public Set getOwnIdentites() throws IOException, FcpException { + return getOwnIdentities(); + } + + /** + * Returns all own identities of the web-of-trust plugins. Almost all other + * commands require an {@link OwnIdentity} to return meaningful values. + * + * @return All own identities of the web-of-trust plugin + * @throws IOException + * if an I/O error occurs + * @throws FcpException + * if an FCP error occurs + */ + public Set getOwnIdentities() throws IOException, FcpException { Map replies = fcpClient.sendPluginMessage(webOfTrustPluginName, createParameters("Message", "GetOwnIdentities")); if (!replies.get("Message").equals("OwnIdentities")) { throw new FcpException("WebOfTrust Plugin did not reply with “OwnIdentities” message!"); diff --git a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java index dab71e0..e8d5f35 100644 --- a/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java +++ b/src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java @@ -134,7 +134,7 @@ public class WebOfTrustPluginTest { public void gettingOwnIdentitiesSendsCorrectMessage() throws Exception { TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); - webOfTrustPlugin.getOwnIdentites(); + webOfTrustPlugin.getOwnIdentities(); assertThat(fcpConnection.sentMessages.get(0), allOf( isNamed(equalTo("FCPPluginMessage")), hasField("Identifier", not(nullValue())), @@ -147,6 +147,34 @@ public class WebOfTrustPluginTest { public void gettingOwnIdentitiesParsesOwnIdentitiesCorrectly() throws Exception { TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities(); WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + Set ownIdentities = webOfTrustPlugin.getOwnIdentities(); + assertThat(ownIdentities, containsInAnyOrder( + allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")), + hasContexts(containsInAnyOrder("test-context-1", "test-context-2")), + hasProperties(allOf(aMapWithSize(2), hasEntry("prop1", "value1"), hasEntry("prop2", "value2")))), + allOf(isOwnIdentity(equalTo("identity-1"), equalTo("Nick 1"), equalTo("request-uri-1"), equalTo("insert-uri-1")), + hasContexts(containsInAnyOrder("test-context-2", "test-context-3")), + hasProperties(allOf(aMapWithSize(2), hasEntry("prop3", "value3"), hasEntry("prop4", "value4")))) + )); + } + + @Test + public void gettingOwnIdentitiesUsingDeprecatedMethodSendsCorrectMessage() throws Exception { + TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); + webOfTrustPlugin.getOwnIdentites(); + assertThat(fcpConnection.sentMessages.get(0), allOf( + isNamed(equalTo("FCPPluginMessage")), + hasField("Identifier", not(nullValue())), + hasField("PluginName", equalTo("plugins.WebOfTrust.WebOfTrust")), + hasField("Param.Message", equalTo("GetOwnIdentities")) + )); + } + + @Test + public void gettingOwnIdentitiesUsingDeprecatedMethodParsesOwnIdentitiesCorrectly() throws Exception { + TestFcpConnection fcpConnection = createConnectionThatDeliversOwnIdentities(); + WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection); Set ownIdentities = webOfTrustPlugin.getOwnIdentites(); assertThat(ownIdentities, containsInAnyOrder( allOf(isOwnIdentity(equalTo("identity-0"), equalTo("Nick 0"), equalTo("request-uri-0"), equalTo("insert-uri-0")), -- 2.7.4