Use method references when possible in test code

See gh-40974
This commit is contained in:
Ahmed Ashour
2024-06-11 12:51:35 -07:00
committed by Phillip Webb
parent dcccb3b2b1
commit 207327d97c
34 changed files with 64 additions and 48 deletions

View File

@@ -115,7 +115,7 @@ class DefaultRunningServiceTests {
}
private DefaultRunningService createRunningService(boolean psResponseHasImage) {
DockerHost host = DockerHost.get("192.168.1.1", () -> Collections.emptyList());
DockerHost host = DockerHost.get("192.168.1.1", Collections::emptyList);
String id = "123";
String name = "my-service";
String image = "redis";

View File

@@ -52,7 +52,7 @@ class DockerHostTests {
private static final Function<String, String> NO_SYSTEM_ENV = (key) -> null;
private static final Supplier<List<DockerCliContextResponse>> NO_CONTEXT = () -> Collections.emptyList();
private static final Supplier<List<DockerCliContextResponse>> NO_CONTEXT = Collections::emptyList;
@Test
void getWhenHasHost() {

View File

@@ -58,14 +58,14 @@ class TcpConnectServiceReadinessCheckTests {
@Test
void checkWhenServerWritesData() throws Exception {
withServer((socket) -> socket.getOutputStream().write('!'), (port) -> check(port));
withServer((socket) -> socket.getOutputStream().write('!'), this::check);
}
@Test
void checkWhenNoSocketOutput() throws Exception {
// Simulate waiting for traffic from client to server. The sleep duration must
// be longer than the read timeout of the ready check!
withServer((socket) -> sleep(Duration.ofSeconds(10)), (port) -> check(port));
withServer((socket) -> sleep(Duration.ofSeconds(10)), this::check);
}
@Test