-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
junit5 compatible version #11
Comments
Linking stefanbirkner/system-rules#55 |
I would like to avoid implementing According to your comment in stefanbirkner/system-rules#55 the only problem why you cannot replace the rule with stefanbirkner/fake-sftp-server-lambda is that you need the port information before the Spring extension starts the application. Am I right? |
Correct |
How did you set the port for the SpringRunner with JUnit 4? |
|
I have a workaround for the lambda solution private static final int String SFTP_SERVER_PORT = freePort();
@AfterAll
public static void afterClass() {
System.clearProperty(DHUB_ENDPOINT_PROPERTY);
}
@BeforeAll
public static void beforeClass() {
System.setProperty(DHUB_ENDPOINT_PROPERTY, "localhost:" + SFTP_SERVER_PORT);
}
@Test
void aTest() {
withSftpServer(server -> {
//your code
});
}
private withSftpServer(
FakeSftpServer.ExceptionThrowingConsumer testCode
) throws Exception {
FakeSftpServer.withSftpServer(server -> {
server.setPort(SFTP_SERVER_PORT);
testCode.accept(server);
});
}
private static freePort() {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
} catch (IOException e) {
throw new RuntimeException(
"Failed to find a free port.",
e
);
}
} Instead of the method |
Glad you guys found a work-around! 🎉 |
And... I can also highly recommend Spring's |
It worked fine. Closing |
Would it be possible to alter the rule so that
@EnableRuleMigrationSupport
would work: https://medium.com/@GalletVictor/migration-from-junit-4-to-junit-5-d8fe38644abeThe text was updated successfully, but these errors were encountered: