Refactor connection failure tests
authorDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 24 Aug 2015 04:29:59 +0000 (06:29 +0200)
committerDavid ‘Bombe’ Roden <bombe@freenetproject.org>
Mon, 24 Aug 2015 04:29:59 +0000 (06:29 +0200)
src/test/java/net/pterodactylus/fcp/quelaton/DefaultFcpClientTest.java

index 3374556..e454798 100644 (file)
@@ -88,29 +88,6 @@ public class DefaultFcpClientTest {
                threadPool.shutdown();
        }
 
-       @Test(expected = ExecutionException.class)
-       public void defaultFcpClientThrowsExceptionIfItCanNotConnect()
-       throws IOException, ExecutionException, InterruptedException {
-               Future<FcpKeyPair> 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<FcpKeyPair> 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<FcpKeyPair> 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<FcpKeyPair> keyPairFuture = fcpClient.generateKeypair().execute();
+                       connectAndAssert(() -> matchesFcpMessage("GenerateSSK"));
+                       fcpServer.close();
+                       keyPairFuture.get();
+               }
+
+       }
+
        public class GenerateKeyPair {
 
                @Test