Skip to content

Commit 1a4871f

Browse files
committed
Extract assertConnectionToSftpServerNotPossible.
Improve readability of the code. The reader can now read the test without knowing how the test checks that it cannot connect to the server. In addition they don't have to understand that the extracted code means that a connection to the server is checked.
1 parent cd72d2a commit 1a4871f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/test/java/com/github/stefanbirkner/fakesftpserver/rule/FakeSftpServerRuleTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,7 @@ public void after_a_successful_test_SFTP_server_is_shutdown() {
572572
() -> {},
573573
sftpServer
574574
);
575-
Throwable exception = exceptionThrownBy(
576-
() -> connectToServer(sftpServer)
577-
);
578-
assertThat(exception).hasCauseInstanceOf(ConnectException.class);
575+
assertConnectionToSftpServerNotPossible(sftpServer);
579576
}
580577

581578
@Test
@@ -587,10 +584,14 @@ public void after_an_erroneous_test_SFTP_server_is_shutdown() {
587584
},
588585
sftpServer
589586
);
590-
Throwable exception = exceptionThrownBy(
591-
() -> connectToServer(sftpServer)
592-
);
593-
assertThat(exception).hasCauseInstanceOf(ConnectException.class);
587+
assertConnectionToSftpServerNotPossible(sftpServer);
588+
}
589+
590+
private void assertConnectionToSftpServerNotPossible(
591+
FakeSftpServerRule sftpServer
592+
) {
593+
assertThatThrownBy(() -> connectToServer(sftpServer))
594+
.hasCauseInstanceOf(ConnectException.class);
594595
}
595596
}
596597

0 commit comments

Comments
 (0)