From: David ‘Bombe’ Roden Date: Mon, 24 Aug 2015 04:29:59 +0000 (+0200) Subject: Refactor connection failure tests X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=10b87473ca4af20eee5c2b55bd6313945a666f97;p=jFCPlib.git Refactor connection failure tests --- diff --git a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java index 3374556..e454798 100644 --- a/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java +++ b/src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java @@ -88,29 +88,6 @@ public class DefaultFcpClientTest { threadPool.shutdown(); } - @Test(expected = ExecutionException.class) - public void defaultFcpClientThrowsExceptionIfItCanNotConnect() - throws IOException, ExecutionException, InterruptedException { - Future keyPairFuture = fcpClient.generateKeypair().execute(); - fcpServer.connect().get(); - fcpServer.collectUntil(is("EndMessage")); - fcpServer.writeLine( - "CloseConnectionDuplicateClientName", - "EndMessage" - ); - keyPairFuture.get(); - } - - @Test(expected = ExecutionException.class) - public void defaultFcpClientThrowsExceptionIfConnectionIsClosed() - throws IOException, ExecutionException, InterruptedException { - Future keyPairFuture = fcpClient.generateKeypair().execute(); - fcpServer.connect().get(); - fcpServer.collectUntil(is("EndMessage")); - fcpServer.close(); - keyPairFuture.get(); - } - private void connectNode() throws InterruptedException, ExecutionException, IOException { fcpServer.connect().get(); fcpServer.collectUntil(is("EndMessage")); @@ -961,6 +938,29 @@ public class DefaultFcpClientTest { assertThat(lines, requestMatcher.get()); } + public class Connections { + + @Test(expected = ExecutionException.class) + public void throwsExceptionOnFailure() throws IOException, ExecutionException, InterruptedException { + Future keyPairFuture = fcpClient.generateKeypair().execute(); + connectAndAssert(() -> matchesFcpMessage("GenerateSSK")); + fcpServer.writeLine( + "CloseConnectionDuplicateClientName", + "EndMessage" + ); + keyPairFuture.get(); + } + + @Test(expected = ExecutionException.class) + public void throwsExceptionIfConnectionIsClosed() throws IOException, ExecutionException, InterruptedException { + Future keyPairFuture = fcpClient.generateKeypair().execute(); + connectAndAssert(() -> matchesFcpMessage("GenerateSSK")); + fcpServer.close(); + keyPairFuture.get(); + } + + } + public class GenerateKeyPair { @Test