From 4505321ee7767d4cae2b06011269ad6e223b6ef8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 4 Sep 2024 22:02:08 +0200 Subject: [PATCH] =?utf8?q?=E2=9C=85=20Add=20test=20for=20getOpennetPeers()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../pterodactylus/fcp/highlevel/FcpClientTest.java | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java index 4a85934..e808c5c 100644 --- a/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/highlevel/FcpClientTest.java @@ -206,6 +206,31 @@ public class FcpClientTest { sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getDarknetPeers, false, false, anything(), contains(peerWithIdentity(equalTo("3")))); } + @Test + public void getOpennetPeersWithMetadataFlagSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getOpennetPeers, true, false, contains(hasField("WithMetadata", equalTo("true"))), anything()); + } + + @Test + public void getOpennetPeersWithMetadataFlagNotSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getOpennetPeers, false, false, contains(hasField("WithMetadata", equalTo("false"))), anything()); + } + + @Test + public void getOpennetPeersWithVolatileFlagSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getOpennetPeers, false, true, contains(hasField("WithVolatile", equalTo("true"))), anything()); + } + + @Test + public void getOpennetPeersWithVolatileFlagNotSetSendsCorrectMessage() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getOpennetPeers, false, false, contains(hasField("WithVolatile", equalTo("false"))), anything()); + } + + @Test + public void getOpennetPeersReturnsPeersWithCorrectIdentifier() throws Exception { + sendListPeersAndVerifySentMessagesAndReturnedPeers(FcpClientTest::getOpennetPeers, false, false, anything(), contains(peerWithIdentity(equalTo("1")))); + } + private static BiFunction> getPeers(FcpClient fcpClient) { return (withMetadata, withVolatile) -> { try { @@ -226,6 +251,16 @@ public class FcpClientTest { }; } + private static BiFunction> getOpennetPeers(FcpClient fcpClient) { + return (withMetadata, withVolatile) -> { + try { + return fcpClient.getOpennetPeers(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 -> { @@ -235,7 +270,7 @@ public class FcpClientTest { String identifier = message.getField("Identifier"); listener.receivedPeer(connection, new Peer(new FcpMessage("Peer").put("Identifier", identifier).put("identity", "1").put("opennet", "true"))); listener.receivedPeer(connection, new Peer(new FcpMessage("Peer").put("Identifier", "Other Identifier").put("identity", "4"))); - listener.receivedPeer(connection, new Peer(new FcpMessage("Peer").put("Identifier", identifier).put("identity", "2").put("seed", "true"))); + listener.receivedPeer(connection, new Peer(new FcpMessage("Peer").put("Identifier", identifier).put("identity", "2").put("opennet", "true").put("seed", "true"))); listener.receivedEndListPeers(connection, new EndListPeers(new FcpMessage("EndListPeers").put("Identifier", "Other Identifier"))); listener.receivedPeer(connection, new Peer(new FcpMessage("Peer").put("Identifier", identifier).put("identity", "3"))); listener.receivedEndListPeers(connection, new EndListPeers(new FcpMessage("EndListPeers").put("Identifier", identifier))); -- 2.7.4