✅ Add more tests for deprecated methods
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 8 Jan 2025 08:24:12 +0000 (09:24 +0100)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Wed, 8 Jan 2025 08:24:12 +0000 (09:24 +0100)
src/test/java/net/pterodactylus/fcp/plugin/WebOfTrustPluginTest.java

index e8d5f35..8139cab 100644 (file)
@@ -120,12 +120,22 @@ public class WebOfTrustPluginTest {
        }
 
        @Test
-       public void creatingIdentityFailsWhenDifferentReplyIsSentByPlugin() {
-               FcpConnection fcpConnection = createFcpConnection(message -> (listener, connection) -> {
-                       Map<String, String> fields = createWebOfTrustReplyFields("OtherMessage", true);
-                       FcpMessage replyMessage = createPluginReply(message, fields);
-                       listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
-               });
+       public void creatingIdentityFailsWithoutKeysFailsWhenDifferentReplyIsSentByPlugin() {
+               FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+               WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+               assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true));
+       }
+
+       @Test
+       public void creatingIdentityFailsWithInsertKeyFailsWhenDifferentReplyIsSentByPlugin() {
+               FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+               WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+               assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "insert-uri"));
+       }
+
+       @Test
+       public void creatingIdentityWithInsertAndRequestKeyFailsWhenDifferentReplyIsSentByPlugin() {
+               FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
                WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
                assertThrows(FcpException.class, () -> webOfTrustPlugin.createIdentity("Test Nickname", "test-context", true, "some-request-uri", "insert-uri"));
        }
@@ -199,6 +209,27 @@ public class WebOfTrustPluginTest {
                });
        }
 
+       @Test
+       public void getOwnIdentitiesFailsWhenDifferentReplyIsSentByPlugin() {
+               FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+               WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+               assertThrows(FcpException.class, webOfTrustPlugin::getOwnIdentities);
+       }
+
+       @Test
+       public void getOwnIdentitiesWithDeprecatedMethodFailsWhenDifferentReplyIsSentByPlugin() {
+               FcpConnection fcpConnection = createConnectionThatSendsOtherMessage();
+               WebOfTrustPlugin webOfTrustPlugin = createWebOfTrustPlugin(fcpConnection);
+               assertThrows(FcpException.class, webOfTrustPlugin::getOwnIdentites);
+       }
+
+       private FcpConnection createConnectionThatSendsOtherMessage() {
+               return createFcpConnection(message -> (listener, connection) -> {
+                       Map<String, String> fields = createWebOfTrustReplyFields("OtherMessage", true);
+                       FcpMessage replyMessage = createPluginReply(message, fields);
+                       listener.receivedFCPPluginReply(connection, new FCPPluginReply(replyMessage, null));
+               });
+       }
 
        private static WebOfTrustPlugin createWebOfTrustPlugin(FcpConnection fcpConnection) {
                return new WebOfTrustPlugin(new FcpClient(fcpConnection));