From da3a336d1d01fcd64b502068d3f76c3f9bd79c74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 6 Sep 2024 13:35:49 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20tests=20for=20getSeedPeers()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/fcp/highlevel/FcpClientTest.java | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java index e808c5c..a307c6c 100644 --- a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java @@ -231,6 +231,31 @@ public class FcpClientTest { sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getOpennetPeers, false, false, anything(), contains(peerWithIdentity(equalTo("1")))); } + @Test + public void getSeedPeersWithMetadataFlagSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, true, false, contains(hasField("WithMetadata", equalTo("true"))), anything()); + } + + @Test + public void getSeedPeersWithMetadataFlagNotSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, false, contains(hasField("WithMetadata", equalTo("false"))), anything()); + } + + @Test + public void getSeedPeersWithVolatileFlagSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, true, contains(hasField("WithVolatile", equalTo("true"))), anything()); + } + + @Test + public void getSeedPeersWithVolatileFlagNotSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, false, contains(hasField("WithVolatile", equalTo("false"))), anything()); + } + + @Test + public void getSeedPeersReturnsPeersWithCorrectIdentifier() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getSeedPeers, false, false, anything(), contains(peerWithIdentity(equalTo("2")))); + } + private static BiFunction> getPeers(FcpClient fcpClient) { return (withMetadata, withVolatile) -> { try { @@ -261,6 +286,16 @@ public class FcpClientTest { }; } + private static BiFunction> getSeedPeers(FcpClient fcpClient) { + return (withMetadata, withVolatile) -> { + try { + return fcpClient.getSeedPeers(withMetadata, withVolatile); + } catch (IOException | FcpException e) { + throw new RuntimeException(e); + } + }; + } + private static void sendListPeersAndVerifySentMessagesAndReturnedPeers(Function>> peerRetrieval, boolean withMetadataFlag, boolean withVolatileFlag, Matcher> sentMessagesMatcher, Matcher> peersMatcher) throws IOException, FcpException { List sentMessages = new ArrayList<>(); FcpConnection fcpConnection = createFcpConnection(message -> { -- 2.7.4