Browse Source

Add nullability annotations to tests in core/spring-boot-docker-compose

See gh-47263
pull/47387/head
Moritz Halbritter 3 months ago
parent
commit
b566b73be6
  1. 8
      core/spring-boot-docker-compose/build.gradle
  2. 3
      core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeIntegrationTests.java
  3. 1
      core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java
  4. 3
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DefaultRunningServiceTests.java
  5. 4
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeFileTests.java
  6. 1
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeOriginTests.java
  7. 3
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerHostTests.java
  8. 1
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/ImageNameTests.java
  9. 16
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManagerTests.java
  10. 5
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeListenerTests.java
  11. 8
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/ServiceReadinessChecksTests.java
  12. 3
      core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/ConnectionNamePredicateTests.java

8
core/spring-boot-docker-compose/build.gradle

@ -38,3 +38,11 @@ dependencies { @@ -38,3 +38,11 @@ dependencies {
testFixturesImplementation(project(":test-support:spring-boot-docker-test-support"))
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
tasks.named("compileDockerTestJava") {
options.nullability.checking = "tests"
}

3
core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DefaultDockerComposeIntegrationTests.java

@ -27,6 +27,7 @@ import java.util.List; @@ -27,6 +27,7 @@ import java.util.List;
import java.util.Set;
import org.assertj.core.api.Assertions;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -88,7 +89,7 @@ class DefaultDockerComposeIntegrationTests { @@ -88,7 +89,7 @@ class DefaultDockerComposeIntegrationTests {
}
}
private RunningService findService(List<RunningService> runningServices, String serviceName) {
private @Nullable RunningService findService(List<RunningService> runningServices, String serviceName) {
for (RunningService runningService : runningServices) {
if (runningService.name().contains(serviceName)) {
return runningService;

1
core/spring-boot-docker-compose/src/dockerTest/java/org/springframework/boot/docker/compose/core/DockerCliIntegrationTests.java

@ -59,6 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -59,6 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class DockerCliIntegrationTests {
@TempDir
@SuppressWarnings("NullAway.Init")
private static Path tempDir;
@Test

3
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DefaultRunningServiceTests.java

@ -47,6 +47,7 @@ import static org.assertj.core.api.Assertions.entry; @@ -47,6 +47,7 @@ import static org.assertj.core.api.Assertions.entry;
class DefaultRunningServiceTests {
@TempDir
@SuppressWarnings("NullAway.Init")
File temp;
private DefaultRunningService runningService;
@ -126,7 +127,7 @@ class DefaultRunningServiceTests { @@ -126,7 +127,7 @@ class DefaultRunningServiceTests {
Map<String, ExposedPort> exposedPorts = Map.of("8080/tcp", new ExposedPort());
List<String> env = List.of("a=b");
Config config = new Config(image, labels, exposedPorts, env);
Map<String, List<HostPort>> ports = Map.of("8080/tcp", List.of(new HostPort(null, "9090")));
Map<String, List<HostPort>> ports = Map.of("8080/tcp", List.of(new HostPort("127.0.0.1", "9090")));
NetworkSettings networkSettings = new NetworkSettings(ports);
HostConfig hostConfig = new HostConfig("bridge");
DockerCliInspectResponse inspectResponse = new DockerCliInspectResponse(id, config, networkSettings,

4
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeFileTests.java

@ -39,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -39,6 +39,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
class DockerComposeFileTests {
@TempDir
@SuppressWarnings("NullAway.Init")
File temp;
@Test
@ -74,6 +75,7 @@ class DockerComposeFileTests { @@ -74,6 +75,7 @@ class DockerComposeFileTests {
File file = new File(this.temp, "docker-compose.yml").getCanonicalFile();
FileCopyUtils.copy(new byte[0], file);
DockerComposeFile composeFile = DockerComposeFile.find(file.getParentFile());
assertThat(composeFile).isNotNull();
assertThat(composeFile.getFiles()).containsExactly(file);
}
@ -84,6 +86,7 @@ class DockerComposeFileTests { @@ -84,6 +86,7 @@ class DockerComposeFileTests {
File f2 = new File(this.temp, "compose.yml").getCanonicalFile();
FileCopyUtils.copy(new byte[0], f2);
DockerComposeFile composeFile = DockerComposeFile.find(f1.getParentFile());
assertThat(composeFile).isNotNull();
assertThat(composeFile.getFiles()).containsExactly(f2);
}
@ -127,6 +130,7 @@ class DockerComposeFileTests { @@ -127,6 +130,7 @@ class DockerComposeFileTests {
}
@Test
@SuppressWarnings("NullAway") // Test null check
void ofWhenFileIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> DockerComposeFile.of((File) null))
.withMessage("'file' must not be null");

1
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerComposeOriginTests.java

@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; @@ -37,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
class DockerComposeOriginTests {
@TempDir
@SuppressWarnings("NullAway.Init")
File temp;
@Test

3
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/DockerHostTests.java

@ -23,6 +23,7 @@ import java.util.Map; @@ -23,6 +23,7 @@ import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -50,7 +51,7 @@ class DockerHostTests { @@ -50,7 +51,7 @@ class DockerHostTests {
private static final String TCP_HOST = "tcp://192.168.1.1";
private static final Function<String, String> NO_SYSTEM_ENV = (key) -> null;
private static final Function<String, @Nullable String> NO_SYSTEM_ENV = (key) -> null;
private static final Supplier<List<DockerCliContextResponse>> NO_CONTEXT = Collections::emptyList;

1
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/core/ImageNameTests.java

@ -116,6 +116,7 @@ class ImageNameTests { @@ -116,6 +116,7 @@ class ImageNameTests {
}
@Test
@SuppressWarnings("NullAway") // Test null check
void ofWhenNameIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> ImageName.of(null))
.withMessage("'value' must not be empty");

16
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeLifecycleManagerTests.java

@ -27,6 +27,7 @@ import java.util.List; @@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@ -68,15 +69,16 @@ import static org.mockito.Mockito.never; @@ -68,15 +69,16 @@ import static org.mockito.Mockito.never;
class DockerComposeLifecycleManagerTests {
@TempDir
@SuppressWarnings("NullAway.Init")
File temp;
private DockerComposeFile dockerComposeFile;
private DockerCompose dockerCompose;
private Set<String> activeProfiles;
private @Nullable Set<String> activeProfiles;
private List<String> arguments;
private @Nullable List<String> arguments;
private GenericApplicationContext applicationContext;
@ -84,7 +86,7 @@ class DockerComposeLifecycleManagerTests { @@ -84,7 +86,7 @@ class DockerComposeLifecycleManagerTests {
private ServiceReadinessChecks serviceReadinessChecks;
private List<RunningService> runningServices;
private @Nullable List<RunningService> runningServices;
private DockerComposeProperties properties;
@ -316,6 +318,7 @@ class DockerComposeLifecycleManagerTests { @@ -316,6 +318,7 @@ class DockerComposeLifecycleManagerTests {
setUpRunningServices();
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(this.runningServices).isNotNull();
then(this.serviceReadinessChecks).should().waitUntilReady(this.runningServices);
}
@ -327,6 +330,7 @@ class DockerComposeLifecycleManagerTests { @@ -327,6 +330,7 @@ class DockerComposeLifecycleManagerTests {
setUpRunningServices();
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(this.runningServices).isNotNull();
then(this.serviceReadinessChecks).should(never()).waitUntilReady(this.runningServices);
}
@ -339,6 +343,7 @@ class DockerComposeLifecycleManagerTests { @@ -339,6 +343,7 @@ class DockerComposeLifecycleManagerTests {
setUpRunningServices();
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(this.runningServices).isNotNull();
then(this.serviceReadinessChecks).should(never()).waitUntilReady(this.runningServices);
}
@ -350,6 +355,7 @@ class DockerComposeLifecycleManagerTests { @@ -350,6 +355,7 @@ class DockerComposeLifecycleManagerTests {
setUpRunningServices(false);
this.lifecycleManager.start();
this.shutdownHandlers.run();
assertThat(this.runningServices).isNotNull();
then(this.serviceReadinessChecks).should().waitUntilReady(this.runningServices);
}
@ -498,14 +504,14 @@ class DockerComposeLifecycleManagerTests { @@ -498,14 +504,14 @@ class DockerComposeLifecycleManagerTests {
*/
static class EventCapturingListener implements ApplicationListener<DockerComposeServicesReadyEvent> {
private DockerComposeServicesReadyEvent event;
private @Nullable DockerComposeServicesReadyEvent event;
@Override
public void onApplicationEvent(DockerComposeServicesReadyEvent event) {
this.event = event;
}
DockerComposeServicesReadyEvent getEvent() {
@Nullable DockerComposeServicesReadyEvent getEvent() {
return this.event;
}

5
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/DockerComposeListenerTests.java

@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.lifecycle; @@ -18,6 +18,7 @@ package org.springframework.boot.docker.compose.lifecycle;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.springframework.boot.SpringApplication;
@ -60,7 +61,7 @@ class DockerComposeListenerTests { @@ -60,7 +61,7 @@ class DockerComposeListenerTests {
private final ConfigurableApplicationContext context;
private DockerComposeLifecycleManager manager;
private @Nullable DockerComposeLifecycleManager manager;
TestDockerComposeListener(SpringApplicationShutdownHandlers shutdownHandlers,
ConfigurableApplicationContext context) {
@ -79,7 +80,7 @@ class DockerComposeListenerTests { @@ -79,7 +80,7 @@ class DockerComposeListenerTests {
return this.manager;
}
DockerComposeLifecycleManager getManager() {
@Nullable DockerComposeLifecycleManager getManager() {
return this.manager;
}

8
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/lifecycle/ServiceReadinessChecksTests.java

@ -23,10 +23,12 @@ import java.util.ArrayList; @@ -23,10 +23,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.lifecycle.DockerComposeProperties.Readiness.Tcp;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@ -103,7 +105,7 @@ class ServiceReadinessChecksTests { @@ -103,7 +105,7 @@ class ServiceReadinessChecksTests {
*/
static class MockServiceReadinessCheck extends TcpConnectServiceReadinessCheck {
private final Integer failUntil;
private final @Nullable Integer failUntil;
private final List<RunningService> checked = new ArrayList<>();
@ -111,8 +113,8 @@ class ServiceReadinessChecksTests { @@ -111,8 +113,8 @@ class ServiceReadinessChecksTests {
this(null);
}
MockServiceReadinessCheck(Integer failUntil) {
super(null);
MockServiceReadinessCheck(@Nullable Integer failUntil) {
super(new Tcp());
this.failUntil = failUntil;
}

3
core/spring-boot-docker-compose/src/test/java/org/springframework/boot/docker/compose/service/connection/ConnectionNamePredicateTests.java

@ -19,6 +19,7 @@ package org.springframework.boot.docker.compose.service.connection; @@ -19,6 +19,7 @@ package org.springframework.boot.docker.compose.service.connection;
import java.util.Map;
import java.util.function.Predicate;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.springframework.boot.docker.compose.core.ImageReference;
@ -96,7 +97,7 @@ class ConnectionNamePredicateTests { @@ -96,7 +97,7 @@ class ConnectionNamePredicateTests {
return sourceOf(connectionName, null);
}
private DockerComposeConnectionSource sourceOf(String connectionName, String label) {
private DockerComposeConnectionSource sourceOf(String connectionName, @Nullable String label) {
DockerComposeConnectionSource source = mock(DockerComposeConnectionSource.class);
RunningService runningService = mock(RunningService.class);
given(source.getRunningService()).willReturn(runningService);

Loading…
Cancel
Save