diff --git a/buildpack/spring-boot-buildpack-platform/build.gradle b/buildpack/spring-boot-buildpack-platform/build.gradle index a0f7eae75ee..7cebb2ecac7 100644 --- a/buildpack/spring-boot-buildpack-platform/build.gradle +++ b/buildpack/spring-boot-buildpack-platform/build.gradle @@ -37,3 +37,11 @@ dependencies { testImplementation(project(":test-support:spring-boot-test-support")) } + +tasks.named("compileTestJava") { + options.nullability.checking = "tests" +} + +tasks.named("compileDockerTestJava") { + options.nullability.checking = "tests" +} diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildOwnerTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildOwnerTests.java index 5fe55d719d6..f4b7ac09ce6 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildOwnerTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildOwnerTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.buildpack.platform.build; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -35,7 +36,7 @@ class BuildOwnerTests { @Test void fromEnvReturnsOwner() { - Map env = new LinkedHashMap<>(); + Map env = new LinkedHashMap<>(); env.put("CNB_USER_ID", "123"); env.put("CNB_GROUP_ID", "456"); BuildOwner owner = BuildOwner.fromEnv(env); @@ -45,6 +46,7 @@ class BuildOwnerTests { } @Test + @SuppressWarnings("NullAway") // Test null check void fromEnvWhenEnvIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> BuildOwner.fromEnv(null)) .withMessage("'env' must not be null"); @@ -52,7 +54,7 @@ class BuildOwnerTests { @Test void fromEnvWhenUserPropertyIsMissingThrowsException() { - Map env = new LinkedHashMap<>(); + Map env = new LinkedHashMap<>(); env.put("CNB_GROUP_ID", "456"); assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env)) .withMessage("Missing 'CNB_USER_ID' value from the builder environment '" + env + "'"); @@ -60,7 +62,7 @@ class BuildOwnerTests { @Test void fromEnvWhenGroupPropertyIsMissingThrowsException() { - Map env = new LinkedHashMap<>(); + Map env = new LinkedHashMap<>(); env.put("CNB_USER_ID", "123"); assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env)) .withMessage("Missing 'CNB_GROUP_ID' value from the builder environment '" + env + "'"); @@ -68,7 +70,7 @@ class BuildOwnerTests { @Test void fromEnvWhenUserPropertyIsMalformedThrowsException() { - Map env = new LinkedHashMap<>(); + Map env = new LinkedHashMap<>(); env.put("CNB_USER_ID", "nope"); env.put("CNB_GROUP_ID", "456"); assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env)) @@ -77,7 +79,7 @@ class BuildOwnerTests { @Test void fromEnvWhenGroupPropertyIsMalformedThrowsException() { - Map env = new LinkedHashMap<>(); + Map env = new LinkedHashMap<>(); env.put("CNB_USER_ID", "123"); env.put("CNB_GROUP_ID", "nope"); assertThatIllegalStateException().isThrownBy(() -> BuildOwner.fromEnv(env)) diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildRequestTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildRequestTests.java index 9d00699e379..7bbb13d3e72 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildRequestTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildRequestTests.java @@ -61,6 +61,7 @@ class BuildRequestTests { private static final ZoneId UTC = ZoneId.of("UTC"); @TempDir + @SuppressWarnings("NullAway.Init") File tempDir; @Test @@ -86,6 +87,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void forJarFileWhenJarFileIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> BuildRequest.forJarFile(null)) .withMessage("'jarFile' must not be null"); @@ -214,6 +216,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void withEnvWhenKeyIsNullThrowsException() throws IOException { BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")); assertThatIllegalArgumentException().isThrownBy(() -> request.withEnv(null, "test")) @@ -221,6 +224,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void withEnvWhenValueIsNullThrowsException() throws IOException { BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")); assertThatIllegalArgumentException().isThrownBy(() -> request.withEnv("test", null)) @@ -238,6 +242,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void withBuildpacksWhenBuildpacksIsNullThrowsException() throws IOException { BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")); assertThatIllegalArgumentException().isThrownBy(() -> request.withBuildpacks((List) null)) @@ -255,6 +260,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void withBindingsWhenBindingsIsNullThrowsException() throws IOException { BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")); assertThatIllegalArgumentException().isThrownBy(() -> request.withBindings((List) null)) @@ -280,6 +286,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void withTagsWhenTagsIsNullThrowsException() throws IOException { BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")); assertThatIllegalArgumentException().isThrownBy(() -> request.withTags((List) null)) @@ -319,6 +326,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void withBuildVolumeCacheWhenCacheIsNullThrowsException() throws IOException { BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")); assertThatIllegalArgumentException().isThrownBy(() -> request.withBuildCache(null)) @@ -342,6 +350,7 @@ class BuildRequestTests { } @Test + @SuppressWarnings("NullAway") // Test null check void withLaunchVolumeCacheWhenCacheIsNullThrowsException() throws IOException { BuildRequest request = BuildRequest.forJarFile(writeTestJarFile("my-app-0.0.1.jar")); assertThatIllegalArgumentException().isThrownBy(() -> request.withLaunchCache(null)) diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java index 19a1bee758c..47e9bc99fc8 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderBuildpackTests.java @@ -51,6 +51,7 @@ class BuilderBuildpackTests extends AbstractJsonTests { void resolveWhenFullyQualifiedBuildpackWithVersionResolves() throws Exception { BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:paketo-buildpacks/spring-boot@3.5.0"); Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()) .isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0")); assertThatNoLayersAreAdded(buildpack); @@ -60,6 +61,7 @@ class BuilderBuildpackTests extends AbstractJsonTests { void resolveWhenFullyQualifiedBuildpackWithoutVersionResolves() throws Exception { BuildpackReference reference = BuildpackReference.of("urn:cnb:builder:paketo-buildpacks/spring-boot"); Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()) .isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0")); assertThatNoLayersAreAdded(buildpack); @@ -69,6 +71,7 @@ class BuilderBuildpackTests extends AbstractJsonTests { void resolveWhenUnqualifiedBuildpackWithVersionResolves() throws Exception { BuildpackReference reference = BuildpackReference.of("paketo-buildpacks/spring-boot@3.5.0"); Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()) .isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0")); assertThatNoLayersAreAdded(buildpack); @@ -78,6 +81,7 @@ class BuilderBuildpackTests extends AbstractJsonTests { void resolveWhenUnqualifiedBuildpackWithoutVersionResolves() throws Exception { BuildpackReference reference = BuildpackReference.of("paketo-buildpacks/spring-boot"); Buildpack buildpack = BuilderBuildpack.resolve(this.resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()) .isEqualTo(BuildpackCoordinates.of("paketo-buildpacks/spring-boot", "3.5.0")); assertThatNoLayersAreAdded(buildpack); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java index 92cb0920e54..28ee1a22b1f 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderMetadataTests.java @@ -88,6 +88,7 @@ class BuilderMetadataTests extends AbstractJsonTests { } @Test + @SuppressWarnings("NullAway") // Test null check void fromImageWhenImageIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> BuilderMetadata.fromImage(null)) .withMessage("'image' must not be null"); @@ -150,6 +151,7 @@ class BuilderMetadataTests extends AbstractJsonTests { BuilderMetadata metadata = BuilderMetadata.fromImage(image); ImageConfig imageConfigCopy = imageConfig.copy(metadata::attachTo); String label = imageConfigCopy.getLabels().get("io.buildpacks.builder.metadata"); + assertThat(label).isNotNull(); BuilderMetadata metadataCopy = BuilderMetadata.fromJson(label); assertThat(metadataCopy.getStack().getRunImage().getImage()) .isEqualTo(metadata.getStack().getRunImage().getImage()); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java index f072b36c291..09ffe850102 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuilderTests.java @@ -20,7 +20,9 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; import java.net.URI; +import java.util.Objects; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.stubbing.Answer; @@ -77,6 +79,7 @@ class BuilderTests { private static final ImageReference BASE_CNB = ImageReference.of("docker.io/cloudfoundry/run:base-cnb"); @Test + @SuppressWarnings("NullAway") // Test null check void createWhenLogIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> new Builder((BuildLog) null)) .withMessage("'log' must not be null"); @@ -106,6 +109,7 @@ class BuilderTests { } @Test + @SuppressWarnings("NullAway") // Test null check void buildWhenRequestIsNullThrowsException() { Builder builder = new Builder(); assertThatIllegalArgumentException().isThrownBy(() -> builder.build(null)) @@ -131,7 +135,9 @@ class BuilderTests { then(docker.image()).should().pull(eq(DEFAULT_BUILDER), isNull(), any(), isNull()); then(docker.image()).should().pull(eq(BASE_CNB), eq(ImagePlatform.from(builderImage)), any(), isNull()); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); then(docker.image()).shouldHaveNoMoreInteractions(); } @@ -161,7 +167,9 @@ class BuilderTests { .pull(eq(BASE_CNB), eq(ImagePlatform.from(builderImage)), any(), regAuthEq(builderToken)); then(docker.image()).should().push(eq(request.getName()), any(), regAuthEq(publishToken)); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); then(docker.image()).shouldHaveNoMoreInteractions(); } @@ -184,7 +192,9 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); } @Test @@ -207,7 +217,9 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); } @Test @@ -227,7 +239,9 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); } @Test @@ -249,7 +263,9 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); } @Test @@ -271,7 +287,9 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); then(docker.image()).should(never()).pull(any(), any(), any()); then(docker.image()).should(times(2)).inspect(any()); } @@ -295,7 +313,9 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); then(docker.image()).should(times(2)).pull(any(), any(), any(), isNull()); then(docker.image()).should(never()).inspect(any()); } @@ -325,7 +345,9 @@ class BuilderTests { assertThat(out.toString()).contains("Successfully built image 'docker.io/library/my-application:latest'"); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); then(docker.image()).should(times(2)).inspect(any()); then(docker.image()).should(times(2)).pull(any(), any(), any(), isNull()); } @@ -349,7 +371,9 @@ class BuilderTests { then(docker.image()).should().tag(eq(request.getName()), eq(ImageReference.of("my-application:1.2.3"))); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); } @Test @@ -385,7 +409,9 @@ class BuilderTests { then(docker.image()).should().push(eq(builtImageReference), any(), regAuthEq(publishToken)); ArgumentCaptor archive = ArgumentCaptor.forClass(ImageArchive.class); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); then(docker.image()).shouldHaveNoMoreInteractions(); } @@ -408,7 +434,9 @@ class BuilderTests { then(docker.image()).should().pull(eq(DEFAULT_BUILDER), eq(platform), any(), isNull()); then(docker.image()).should().pull(eq(BASE_CNB), eq(platform), any(), isNull()); then(docker.image()).should().load(archive.capture(), any()); - then(docker.image()).should().remove(archive.getValue().getTag(), true); + ImageReference tag = archive.getValue().getTag(); + assertThat(tag).isNotNull(); + then(docker.image()).should().remove(tag, true); then(docker.image()).shouldHaveNoMoreInteractions(); } @@ -483,7 +511,7 @@ class BuilderTests { return mockDockerApi(null); } - private DockerApi mockDockerApi(ImagePlatform platform) throws IOException { + private DockerApi mockDockerApi(@Nullable ImagePlatform platform) throws IOException { ContainerApi containerApi = mock(ContainerApi.class); ContainerReference reference = ContainerReference.of("container-ref"); given(containerApi.create(any(), eq(platform), any())).willReturn(reference); @@ -531,7 +559,7 @@ class BuilderTests { } private static String regAuthEq(DockerRegistryAuthentication authentication) { - return argThat(authentication.getAuthHeader()::equals); + return argThat((arg) -> Objects.equals(authentication.getAuthHeader(), arg)); } static class TestPrintStream extends PrintStream { diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackCoordinatesTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackCoordinatesTests.java index fe4d4b7da17..e8bfc71a572 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackCoordinatesTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackCoordinatesTests.java @@ -23,6 +23,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.nio.file.Paths; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; @@ -97,6 +98,7 @@ class BuildpackCoordinatesTests extends AbstractJsonTests { } @Test + @SuppressWarnings("NullAway") // Test null check void fromBuildpackMetadataWhenMetadataIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> BuildpackCoordinates.fromBuildpackMetadata(null)) .withMessage("'buildpackMetadata' must not be null"); @@ -111,6 +113,7 @@ class BuildpackCoordinatesTests extends AbstractJsonTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenIdIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> BuildpackCoordinates.of(null, null)) .withMessage("'id' must not be empty"); @@ -155,7 +158,8 @@ class BuildpackCoordinatesTests extends AbstractJsonTests { assertThat(c1a).hasSameHashCodeAs(c1b); } - private InputStream createTomlStream(String id, String version, boolean includeStacks, boolean includeOrder) { + private InputStream createTomlStream(@Nullable String id, @Nullable String version, boolean includeStacks, + boolean includeOrder) { StringBuilder builder = new StringBuilder(); builder.append("[buildpack]\n"); if (id != null) { diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java index 7c2f660c8a9..cd1eb067320 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackLayersMetadataTests.java @@ -53,6 +53,7 @@ class BuildpackLayersMetadataTests extends AbstractJsonTests { } @Test + @SuppressWarnings("NullAway") // Test null check void fromImageWhenImageIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> BuildpackLayersMetadata.fromImage(null)) .withMessage("'image' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java index 170dbb19d91..b6d36c1a36b 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/BuildpackMetadataTests.java @@ -47,6 +47,7 @@ class BuildpackMetadataTests extends AbstractJsonTests { } @Test + @SuppressWarnings("NullAway") // Test null check void fromImageWhenImageIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> BuildpackMetadata.fromImage(null)) .withMessage("'image' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java index 6526827781a..b25d292cbdb 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/DirectoryBuildpackTests.java @@ -50,6 +50,7 @@ import static org.mockito.Mockito.mock; class DirectoryBuildpackTests { @TempDir + @SuppressWarnings("NullAway.Init") File temp; private File buildpackDir; diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java index 6b1de4d08b0..4fc81396e1e 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/EphemeralBuilderTests.java @@ -35,6 +35,7 @@ import java.util.Map; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -61,6 +62,7 @@ class EphemeralBuilderTests extends AbstractJsonTests { private static final int EXISTING_IMAGE_LAYER_COUNT = 43; @TempDir + @SuppressWarnings("NullAway.Init") File temp; private final BuildOwner owner = BuildOwner.of(123, 456); @@ -73,7 +75,7 @@ class EphemeralBuilderTests extends AbstractJsonTests { private Map env; - private Buildpacks buildpacks; + private @Nullable Buildpacks buildpacks; private final Creator creator = Creator.withVersion("dev"); @@ -112,6 +114,7 @@ class EphemeralBuilderTests extends AbstractJsonTests { EphemeralBuilder builder = new EphemeralBuilder(this.owner, this.image, this.targetImage, this.metadata, this.creator, this.env, this.buildpacks); ImageReference tag = builder.getArchive(null).getTag(); + assertThat(tag).isNotNull(); assertThat(tag.toString()).startsWith("pack.local/builder/").endsWith(":latest"); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java index dadfc07d89c..0dff53c1b6b 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/ImageBuildpackTests.java @@ -30,6 +30,7 @@ import java.util.Random; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; @@ -79,6 +80,7 @@ class ImageBuildpackTests extends AbstractJsonTests { willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any()); BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:1.0.0"); Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1"); assertAppliesExpectedLayers(buildpack); } @@ -93,6 +95,7 @@ class ImageBuildpackTests extends AbstractJsonTests { willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any()); BuildpackReference reference = BuildpackReference.of("example/buildpack1:1.0.0"); Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1"); assertAppliesExpectedLayers(buildpack); } @@ -107,6 +110,7 @@ class ImageBuildpackTests extends AbstractJsonTests { willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any()); BuildpackReference reference = BuildpackReference.of("example/buildpack1"); Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1"); assertAppliesExpectedLayers(buildpack); } @@ -122,6 +126,7 @@ class ImageBuildpackTests extends AbstractJsonTests { willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any()); BuildpackReference reference = BuildpackReference.of("example/buildpack1@" + digest); Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1"); assertAppliesExpectedLayers(buildpack); } @@ -137,6 +142,7 @@ class ImageBuildpackTests extends AbstractJsonTests { willAnswer(this::withMockLayers).given(resolverContext).exportImageLayers(eq(imageReference), any()); BuildpackReference reference = BuildpackReference.of("docker://example/buildpack1:1.0.0"); Buildpack buildpack = ImageBuildpack.resolve(resolverContext, reference); + assertThat(buildpack).isNotNull(); assertThat(buildpack.getCoordinates()).hasToString("example/hello-universe@0.0.1"); assertAppliesNoLayers(buildpack); } @@ -177,7 +183,7 @@ class ImageBuildpackTests extends AbstractJsonTests { assertThat(buildpack).isNull(); } - private Object withMockLayers(InvocationOnMock invocation) { + private @Nullable Object withMockLayers(InvocationOnMock invocation) { try { IOBiConsumer consumer = invocation.getArgument(1); File tarFile = File.createTempFile("create-builder-test-", null); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java index ac356ee526a..5ad2ce07653 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleTests.java @@ -29,6 +29,7 @@ import java.util.Map; import com.sun.jna.Platform; import org.json.JSONException; import org.json.JSONObject; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -500,7 +501,9 @@ class LifecycleTests { then(this.docker.container()).should().start(containerReference); then(this.docker.container()).should().logs(eq(containerReference), any()); then(this.docker.container()).should().remove(containerReference, true); - configConsumer.accept(this.configs.get(containerReference.toString())); + ContainerConfig containerConfig = this.configs.get(containerReference.toString()); + assertThat(containerConfig).isNotNull(); + configConsumer.accept(containerConfig); } private IOConsumer withExpectedConfig(String name) { @@ -527,7 +530,7 @@ class LifecycleTests { static class TestLifecycle extends Lifecycle { - TestLifecycle(BuildLog log, DockerApi docker, ResolvedDockerHost dockerHost, BuildRequest request, + TestLifecycle(BuildLog log, DockerApi docker, @Nullable ResolvedDockerHost dockerHost, BuildRequest request, EphemeralBuilder builder) { super(log, docker, dockerHost, request, builder); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleVersionTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleVersionTests.java index 12a037949b5..d279506c44a 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleVersionTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/LifecycleVersionTests.java @@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class LifecycleVersionTests { @Test + @SuppressWarnings("NullAway") // Test null check void parseWhenValueIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> LifecycleVersion.parse(null)) .withMessage("'value' must not be empty"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/StackIdTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/StackIdTests.java index 7c390970ac0..8a0cdaf935f 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/StackIdTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/StackIdTests.java @@ -36,6 +36,7 @@ import static org.mockito.Mockito.mock; class StackIdTests { @Test + @SuppressWarnings("NullAway") // Test null check void fromImageWhenImageIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> StackId.fromImage(null)) .withMessage("'image' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestBuildpack.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestBuildpack.java index b259603fc7d..b99f941e39e 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestBuildpack.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/build/TestBuildpack.java @@ -18,6 +18,8 @@ package org.springframework.boot.buildpack.platform.build; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.buildpack.platform.docker.type.Layer; import org.springframework.boot.buildpack.platform.io.Content; import org.springframework.boot.buildpack.platform.io.IOConsumer; @@ -34,7 +36,7 @@ class TestBuildpack implements Buildpack { private final BuildpackCoordinates coordinates; - TestBuildpack(String id, String version) { + TestBuildpack(String id, @Nullable String version) { this.coordinates = BuildpackCoordinates.of(id, version); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ApiVersionTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ApiVersionTests.java index c2e01b4f771..0eb4eda4eec 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ApiVersionTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ApiVersionTests.java @@ -32,6 +32,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class ApiVersionTests { @Test + @SuppressWarnings("NullAway") // Test null check void parseWhenVersionIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> ApiVersion.parse(null)) .withMessage("'value' must not be empty"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java index 1f38cec7916..9006aee724a 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/DockerApiTests.java @@ -29,6 +29,7 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.message.BasicHeader; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -102,6 +103,7 @@ class DockerApiTests { private static final String VOLUMES_URL = API_URL + "/volumes"; @Mock + @SuppressWarnings("NullAway.Init") private HttpTransport http; private DockerApi dockerApi; @@ -119,7 +121,7 @@ class DockerApiTests { return responseOf(null); } - private Response responseOf(String name) { + private Response responseOf(@Nullable String name) { return new Response() { @Override @@ -129,7 +131,7 @@ class DockerApiTests { @Override public InputStream getContent() { if (name == null) { - return null; + return new ByteArrayInputStream(new byte[0]); } return getClass().getResourceAsStream(name); } @@ -142,11 +144,11 @@ class DockerApiTests { @Override public InputStream getContent() { - return null; + return new ByteArrayInputStream(new byte[0]); } @Override - public Header getHeader(String name) { + public @Nullable Header getHeader(String name) { return Arrays.stream(headers) .filter((header) -> header.getName().equals(name)) .findFirst() @@ -172,15 +174,19 @@ class DockerApiTests { private ImageApi api; @Mock + @SuppressWarnings("NullAway.Init") private UpdateListener pullListener; @Mock + @SuppressWarnings("NullAway.Init") private UpdateListener pushListener; @Mock + @SuppressWarnings("NullAway.Init") private UpdateListener loadListener; @Captor + @SuppressWarnings("NullAway.Init") private ArgumentCaptor> writer; @BeforeEach @@ -189,12 +195,14 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void pullWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.pull(null, null, this.pullListener)) .withMessage("'reference' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void pullWhenListenerIsNullThrowsException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.api.pull(ImageReference.of("ubuntu"), null, null)) @@ -262,12 +270,14 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void pushWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.push(null, this.pushListener, null)) .withMessage("'reference' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void pushWhenListenerIsNullThrowsException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.api.push(ImageReference.of("ubuntu"), null, null)) @@ -297,12 +307,14 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void loadWhenArchiveIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.load(null, UpdateListener.none())) .withMessage("'archive' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void loadWhenListenerIsNullThrowsException() { ImageArchive archive = mock(ImageArchive.class); assertThatIllegalArgumentException().isThrownBy(() -> this.api.load(archive, null)) @@ -347,6 +359,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void removeWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.remove(null, true)) .withMessage("'reference' must not be null"); @@ -375,6 +388,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void inspectWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.inspect(null)) .withMessage("'reference' must not be null"); @@ -446,6 +460,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void tagWhenReferenceIsNullThrowsException() { ImageReference tag = ImageReference.of("localhost:5000/ubuntu"); assertThatIllegalArgumentException().isThrownBy(() -> this.api.tag(null, tag)) @@ -453,6 +468,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void tagWhenTargetIsNullThrowsException() { ImageReference reference = ImageReference.of("localhost:5000/ubuntu"); assertThatIllegalArgumentException().isThrownBy(() -> this.api.tag(reference, null)) @@ -487,9 +503,11 @@ class DockerApiTests { private ContainerApi api; @Captor + @SuppressWarnings("NullAway.Init") private ArgumentCaptor> writer; @Mock + @SuppressWarnings("NullAway.Init") private UpdateListener logListener; @BeforeEach @@ -498,6 +516,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenConfigIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.create(null, null)) .withMessage("'config' must not be null"); @@ -553,7 +572,7 @@ class DockerApiTests { createWithPlatform(null); } - private void createWithPlatform(String apiVersion) throws IOException, URISyntaxException { + private void createWithPlatform(@Nullable String apiVersion) throws IOException, URISyntaxException { ImageReference imageReference = ImageReference.of("ubuntu:bionic"); ContainerConfig config = ContainerConfig.of(imageReference, (update) -> update.withCommand("/bin/bash")); ImagePlatform platform = ImagePlatform.of("linux/arm64/v1"); @@ -585,6 +604,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void startWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.start(null)) .withMessage("'reference' must not be null"); @@ -600,12 +620,14 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void logsWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.logs(null, UpdateListener.none())) .withMessage("'reference' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void logsWhenListenerIsNullThrowsException() { assertThatIllegalArgumentException() .isThrownBy(() -> this.api.logs(ContainerReference.of("e90e34656806"), null)) @@ -625,6 +647,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void waitWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.wait(null)) .withMessage("'reference' must not be null"); @@ -640,6 +663,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void removeWhenReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.remove(null, true)) .withMessage("'reference' must not be null"); @@ -676,6 +700,7 @@ class DockerApiTests { } @Test + @SuppressWarnings("NullAway") // Test null check void deleteWhenNameIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> this.api.delete(null, false)) .withMessage("'name' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ProgressUpdateEventTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ProgressUpdateEventTests.java index d9e27a68c90..9aec1dbb555 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ProgressUpdateEventTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/ProgressUpdateEventTests.java @@ -41,13 +41,17 @@ abstract class ProgressUpdateEventTests { @Test void getProgressDetailReturnsProgressDetails() { ProgressUpdateEvent event = createEvent(); - assertThat(event.getProgressDetail().asPercentage()).isEqualTo(50); + ProgressDetail progressDetail = event.getProgressDetail(); + assertThat(progressDetail).isNotNull(); + assertThat(progressDetail.asPercentage()).isEqualTo(50); } @Test void getProgressDetailReturnsProgressDetailsForLongNumbers() { ProgressUpdateEvent event = createEvent("status", new ProgressDetail(4000000000L, 8000000000L), "progress"); - assertThat(event.getProgressDetail().asPercentage()).isEqualTo(50); + ProgressDetail progressDetail = event.getProgressDetail(); + assertThat(progressDetail).isNotNull(); + assertThat(progressDetail.asPercentage()).isEqualTo(50); } @Test diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PullUpdateEventTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PullUpdateEventTests.java index 681d9d50392..dea84456d19 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PullUpdateEventTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PullUpdateEventTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.buildpack.platform.docker; import org.junit.jupiter.api.Test; +import org.springframework.boot.buildpack.platform.docker.ProgressUpdateEvent.ProgressDetail; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +37,9 @@ class PullUpdateEventTests extends AbstractJsonTests { PullImageUpdateEvent.class); assertThat(event.getId()).isEqualTo("4f4fb700ef54"); assertThat(event.getStatus()).isEqualTo("Extracting"); - assertThat(event.getProgressDetail().asPercentage()).isEqualTo(50); + ProgressDetail progressDetail = event.getProgressDetail(); + assertThat(progressDetail).isNotNull(); + assertThat(progressDetail.asPercentage()).isEqualTo(50); assertThat(event.getProgress()).isEqualTo("[==================================================>] 32B/32B"); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PushImageUpdateEventTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PushImageUpdateEventTests.java index c581916edcd..82f43acff3f 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PushImageUpdateEventTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/PushImageUpdateEventTests.java @@ -19,6 +19,7 @@ package org.springframework.boot.buildpack.platform.docker; import org.junit.jupiter.api.Test; import org.springframework.boot.buildpack.platform.docker.ProgressUpdateEvent.ProgressDetail; +import org.springframework.boot.buildpack.platform.docker.PushImageUpdateEvent.ErrorDetail; import static org.assertj.core.api.Assertions.assertThat; @@ -37,9 +38,11 @@ class PushImageUpdateEventTests extends ProgressUpdateEventTests credentialHelperFactory = this.credentialHelpers::get; return new DockerRegistryConfigAuthentication(fallback, this.helperExceptions::put, this.environment::get, - this.credentialHelpers::get); + credentialHelperFactory); } private void mockHelper(String name, String serverUrl, String credentialsResourceName) throws Exception { @@ -409,8 +426,7 @@ class DockerRegistryConfigAuthenticationTests { } } - private Map decode(String authHeader) throws Exception { - assertThat(authHeader).isNotNull(); + private Map decode(String authHeader) { return SharedJsonMapper.get().readValue(Base64.getDecoder().decode(authHeader), new TypeReference<>() { }); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryUserAuthenticationTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryUserAuthenticationTests.java index c91a357d020..52dce16c75f 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryUserAuthenticationTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryUserAuthenticationTests.java @@ -27,6 +27,8 @@ import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; import org.springframework.util.StreamUtils; +import static org.assertj.core.api.Assertions.assertThat; + /** * Tests for {@link DockerRegistryUserAuthentication}. * @@ -38,13 +40,17 @@ class DockerRegistryUserAuthenticationTests extends AbstractJsonTests { void createMinimalAuthHeaderReturnsEncodedHeader() throws IOException, JSONException { DockerRegistryUserAuthentication auth = new DockerRegistryUserAuthentication("user", "secret", "https://docker.example.com", "docker@example.com"); - JSONAssert.assertEquals(jsonContent("auth-user-full.json"), decoded(auth.getAuthHeader()), true); + String authHeader = auth.getAuthHeader(); + assertThat(authHeader).isNotNull(); + JSONAssert.assertEquals(jsonContent("auth-user-full.json"), decoded(authHeader), true); } @Test void createFullAuthHeaderReturnsEncodedHeader() throws IOException, JSONException { DockerRegistryUserAuthentication auth = new DockerRegistryUserAuthentication("user", "secret", null, null); - JSONAssert.assertEquals(jsonContent("auth-user-minimal.json"), decoded(auth.getAuthHeader()), false); + String authHeader = auth.getAuthHeader(); + assertThat(authHeader).isNotNull(); + JSONAssert.assertEquals(jsonContent("auth-user-minimal.json"), decoded(authHeader), false); } private String jsonContent(String s) throws IOException { diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java index ad130b73d17..8e4545f5f5a 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/ResolvedDockerHostTests.java @@ -212,7 +212,9 @@ class ResolvedDockerHostTests { private String pathToResource(String resource) throws URISyntaxException { URL url = getClass().getResource(resource); - return Paths.get(url.toURI()).getParent().toAbsolutePath().toString(); + Path parent = Paths.get(url.toURI()).getParent(); + assertThat(parent).isNotNull(); + return parent.toAbsolutePath().toString(); } } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerConnectionExceptionTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerConnectionExceptionTests.java index fd571e4890a..00eabf77ae6 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerConnectionExceptionTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerConnectionExceptionTests.java @@ -33,12 +33,14 @@ class DockerConnectionExceptionTests { private static final String HOST = "docker://localhost/"; @Test + @SuppressWarnings("NullAway") // Test null check void createWhenHostIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> new DockerConnectionException(null, null)) .withMessage("'host' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenCauseIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> new DockerConnectionException(HOST, null)) .withMessage("'cause' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerEngineExceptionTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerEngineExceptionTests.java index 0383f0a2123..2773ccc4cc7 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerEngineExceptionTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/DockerEngineExceptionTests.java @@ -54,6 +54,7 @@ class DockerEngineExceptionTests { private static final Message MESSAGE = new Message("response message"); @Test + @SuppressWarnings("NullAway") // Test null check void createWhenHostIsNullThrowsException() { assertThatIllegalArgumentException() .isThrownBy(() -> new DockerEngineException(null, null, 404, null, NO_ERRORS, NO_MESSAGE)) @@ -61,6 +62,7 @@ class DockerEngineExceptionTests { } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenUriIsNullThrowsException() { assertThatIllegalArgumentException() .isThrownBy(() -> new DockerEngineException(HOST, null, 404, null, NO_ERRORS, NO_MESSAGE)) diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java index ee037ea790c..f5a4c98f5f8 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/HttpClientTransportTests.java @@ -67,15 +67,19 @@ class HttpClientTransportTests { private static final String APPLICATION_X_TAR = "application/x-tar"; @Mock + @SuppressWarnings("NullAway.Init") private HttpClient client; @Mock + @SuppressWarnings("NullAway.Init") private ClassicHttpResponse response; @Mock + @SuppressWarnings("NullAway.Init") private HttpEntity entity; @Mock + @SuppressWarnings("NullAway.Init") private InputStream content; private HttpClientTransport http; @@ -294,7 +298,9 @@ class HttpClientTransportTests { assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri)) .satisfies((ex) -> { assertThat(ex.getErrors()).isNull(); - assertThat(ex.getResponseMessage().getMessage()).contains("test message"); + Message responseMessage = ex.getResponseMessage(); + assertThat(responseMessage).isNotNull(); + assertThat(responseMessage.getMessage()).contains("test message"); }); } @@ -318,7 +324,9 @@ class HttpClientTransportTests { assertThatExceptionOfType(DockerEngineException.class).isThrownBy(() -> this.http.get(this.uri)) .satisfies((ex) -> { assertThat(ex.getErrors()).hasSize(2); - assertThat(ex.getResponseMessage().getMessage()).contains("test message"); + Message responseMessage = ex.getResponseMessage(); + assertThat(responseMessage).isNotNull(); + assertThat(responseMessage.getMessage()).contains("test message"); }); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java index abdf693f6c4..b8a5acab296 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/transport/RemoteHttpClientTransportTests.java @@ -68,6 +68,7 @@ class RemoteHttpClientTransportTests { ResolvedDockerHost dockerHost = ResolvedDockerHost .from(new DockerConnectionConfiguration.Host("tcp://192.168.1.2:2376")); RemoteHttpClientTransport transport = RemoteHttpClientTransport.createIfPossible(dockerHost); + assertThat(transport).isNotNull(); assertThat(transport.getHost()).satisfies(hostOf("http", "192.168.1.2", 2376)); } @@ -78,6 +79,7 @@ class RemoteHttpClientTransportTests { ResolvedDockerHost dockerHost = ResolvedDockerHost .from(new DockerConnectionConfiguration.Host("tcp://192.168.1.2:2376", true, "/test-cert-path")); RemoteHttpClientTransport transport = RemoteHttpClientTransport.createIfPossible(dockerHost, sslContextFactory); + assertThat(transport).isNotNull(); assertThat(transport.getHost()).satisfies(hostOf("https", "192.168.1.2", 2376)); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java index 22431019db6..bce998e3213 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/BindingTests.java @@ -39,6 +39,7 @@ class BindingTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofWithNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Binding.of(null)) .withMessageContaining("'value' must not be null"); @@ -51,12 +52,14 @@ class BindingTests { } @Test + @SuppressWarnings("NullAway") // Test null check void fromWithNullSourceThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Binding.from((String) null, "container-dest")) .withMessageContaining("'source' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void fromWithNullDestinationThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Binding.from("host-src", null)) .withMessageContaining("'destination' must not be null"); @@ -69,6 +72,7 @@ class BindingTests { } @Test + @SuppressWarnings("NullAway") // Test null check void fromVolumeNameSourceWithNullSourceThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Binding.from((VolumeName) null, "container-dest")) .withMessageContaining("'sourceVolume' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfigTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfigTests.java index 53d239b12ab..c70db616658 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfigTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerConfigTests.java @@ -37,12 +37,14 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class ContainerConfigTests extends AbstractJsonTests { @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenImageReferenceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> ContainerConfig.of(null, (update) -> { })).withMessage("'imageReference' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenUpdateIsNullThrowsException() { ImageReference imageReference = ImageReference.of("ubuntu:bionic"); assertThatIllegalArgumentException().isThrownBy(() -> ContainerConfig.of(imageReference, null)) diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerContentTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerContentTests.java index 6433db9ca84..b8c5c989f89 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerContentTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerContentTests.java @@ -32,12 +32,14 @@ import static org.mockito.Mockito.mock; class ContainerContentTests { @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenArchiveIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> ContainerContent.of(null)) .withMessage("'archive' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenDestinationPathIsNullThrowsException() { TarArchive archive = mock(TarArchive.class); assertThatIllegalArgumentException().isThrownBy(() -> ContainerContent.of(archive, null)) diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerReferenceTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerReferenceTests.java index 0073de178de..373531d3e13 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerReferenceTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ContainerReferenceTests.java @@ -36,6 +36,7 @@ class ContainerReferenceTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> ContainerReference.of(null)) .withMessage("'value' must not be empty"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageConfigTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageConfigTests.java index 8809a456fc0..457153ed7c8 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageConfigTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageConfigTests.java @@ -18,6 +18,7 @@ package org.springframework.boot.buildpack.platform.docker.type; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; @@ -36,7 +37,7 @@ class ImageConfigTests extends AbstractJsonTests { @Test void getEnvContainsParsedValues() { ImageConfig imageConfig = getImageConfig(); - Map env = imageConfig.getEnv(); + Map env = imageConfig.getEnv(); assertThat(env).contains(entry("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"), entry("CNB_USER_ID", "2000"), entry("CNB_GROUP_ID", "2000"), entry("CNB_STACK_ID", "org.cloudfoundry.stacks.cflinuxfs3")); @@ -45,7 +46,7 @@ class ImageConfigTests extends AbstractJsonTests { @Test void whenConfigHasNoEnvThenImageConfigEnvIsEmpty() { ImageConfig imageConfig = getMinimalImageConfig(); - Map env = imageConfig.getEnv(); + Map env = imageConfig.getEnv(); assertThat(env).isEmpty(); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageNameTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageNameTests.java index 8243b3382e8..5236d4b6ece 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageNameTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageNameTests.java @@ -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"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageReferenceTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageReferenceTests.java index 37a33f07556..fe18066796e 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageReferenceTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageReferenceTests.java @@ -246,6 +246,7 @@ class ImageReferenceTests { } @Test + @SuppressWarnings("NullAway") // Test null check void randomWherePrefixIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> ImageReference.random(null)) .withMessage("'prefix' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java index e43c527ebcc..23ae8d651a6 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/ImageTests.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.boot.buildpack.platform.json.AbstractJsonTests; @@ -37,7 +38,7 @@ class ImageTests extends AbstractJsonTests { @Test void getConfigEnvContainsParsedValues() throws Exception { Image image = getImage(); - Map env = image.getConfig().getEnv(); + Map env = image.getConfig().getEnv(); assertThat(env).contains(entry("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"), entry("CNB_USER_ID", "2000"), entry("CNB_GROUP_ID", "2000"), entry("CNB_STACK_ID", "org.cloudfoundry.stacks.cflinuxfs3")); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerIdTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerIdTests.java index e67c78e5596..f140540ef57 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerIdTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerIdTests.java @@ -50,6 +50,7 @@ class LayerIdTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenValueIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> LayerId.of((String) null)) .withMessage("'value' must not be empty"); @@ -78,6 +79,7 @@ class LayerIdTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofSha256DigestWhenNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> LayerId.ofSha256Digest((byte[]) null)) .withMessage("'digest' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerTests.java index 5e96f472678..833e54d1911 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/LayerTests.java @@ -38,12 +38,14 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class LayerTests { @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenLayoutIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Layer.of((IOConsumer) null)) .withMessage("'layout' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void fromTarArchiveWhenTarArchiveIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Layer.fromTarArchive(null)) .withMessage("'tarArchive' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/RandomStringTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/RandomStringTests.java index 148385ca54c..e467e99e4ab 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/RandomStringTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/RandomStringTests.java @@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class RandomStringTests { @Test + @SuppressWarnings("NullAway") // Test null check void generateWhenPrefixIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> RandomString.generate(null, 10)) .withMessage("'prefix' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/VolumeNameTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/VolumeNameTests.java index 77f76d5c07b..edebf551fc8 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/VolumeNameTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/type/VolumeNameTests.java @@ -29,6 +29,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class VolumeNameTests { @Test + @SuppressWarnings("NullAway") // Test null check void randomWhenPrefixIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.random(null)) .withMessage("'prefix' must not be null"); @@ -55,24 +56,28 @@ class VolumeNameTests { } @Test + @SuppressWarnings("NullAway") // Test null check void basedOnWhenSourceIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn(null, "prefix", "suffix", 6)) .withMessage("'source' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void basedOnWhenNameExtractorIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn("test", null, "prefix", "suffix", 6)) .withMessage("'nameExtractor' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void basedOnWhenPrefixIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn("test", null, "suffix", 6)) .withMessage("'prefix' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void basedOnWhenSuffixIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.basedOn("test", "prefix", null, 6)) .withMessage("'suffix' must not be null"); @@ -91,6 +96,7 @@ class VolumeNameTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenValueIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> VolumeName.of(null)) .withMessage("'value' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ContentTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ContentTests.java index 00f73c10a7e..c53d8452d97 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ContentTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ContentTests.java @@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class ContentTests { @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenSupplierIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Content.of(1, (IOSupplier) null)) .withMessage("'supplier' must not be null"); @@ -49,6 +50,7 @@ class ContentTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenStringIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Content.of((String) null)) .withMessage("'string' must not be null"); @@ -61,6 +63,7 @@ class ContentTests { } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenBytesIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> Content.of((byte[]) null)) .withMessage("'bytes' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/FilePermissionsTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/FilePermissionsTests.java index 94ed6f669f4..3c75e9c7211 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/FilePermissionsTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/FilePermissionsTests.java @@ -45,6 +45,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; class FilePermissionsTests { @TempDir + @SuppressWarnings("NullAway.Init") Path tempDir; @Test @@ -72,6 +73,7 @@ class FilePermissionsTests { } @Test + @SuppressWarnings("NullAway") // Test null check void umaskForPathWithNullPath() { assertThatIllegalArgumentException().isThrownBy(() -> FilePermissions.umaskForPath(null)); } @@ -89,6 +91,7 @@ class FilePermissionsTests { } @Test + @SuppressWarnings("NullAway") // Test null check void posixPermissionsToUmaskWithNullPermissions() { assertThatIllegalArgumentException().isThrownBy(() -> FilePermissions.posixPermissionsToUmask(null)); } diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/InspectedContentTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/InspectedContentTests.java index 097933f0817..62b7f3307b5 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/InspectedContentTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/InspectedContentTests.java @@ -37,18 +37,21 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class InspectedContentTests { @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenInputStreamThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> InspectedContent.of((InputStream) null)) .withMessage("'inputStream' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenContentIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> InspectedContent.of((Content) null)) .withMessage("'content' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void ofWhenConsumerIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> InspectedContent.of((IOConsumer) null)) .withMessage("'writer' must not be null"); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/TarArchiveTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/TarArchiveTests.java index 8739ee3fcd9..ff6d6984a8e 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/TarArchiveTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/TarArchiveTests.java @@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThat; class TarArchiveTests { @TempDir + @SuppressWarnings("NullAway.Init") File tempDir; @Test diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchiveTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchiveTests.java index 62add8c36a6..175752aeec7 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchiveTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/io/ZipFileTarArchiveTests.java @@ -41,15 +41,18 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException class ZipFileTarArchiveTests { @TempDir + @SuppressWarnings("NullAway.Init") File tempDir; @Test + @SuppressWarnings("NullAway") // Test null check void createWhenZipIsNullThrowsException() { assertThatIllegalArgumentException().isThrownBy(() -> new ZipFileTarArchive(null, Owner.ROOT)) .withMessage("'zip' must not be null"); } @Test + @SuppressWarnings("NullAway") // Test null check void createWhenOwnerIsNullThrowsException() throws Exception { File file = new File(this.tempDir, "test.zip"); writeTestZip(file); diff --git a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/json/MappedObjectTests.java b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/json/MappedObjectTests.java index 2d5d9068d92..59d116befe7 100644 --- a/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/json/MappedObjectTests.java +++ b/buildpack/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/json/MappedObjectTests.java @@ -63,6 +63,7 @@ class MappedObjectTests extends AbstractJsonTests { @Test void valueAtWhenInterfaceReturnsProxy() { Person person = this.mapped.valueAt("/person", Person.class); + assertThat(person).isNotNull(); assertThat(person.getName().getFirst()).isEqualTo("spring"); assertThat(person.getName().getLast()).isEqualTo("boot"); } @@ -70,6 +71,7 @@ class MappedObjectTests extends AbstractJsonTests { @Test void valueAtWhenInterfaceAndMissingReturnsProxy() { Person person = this.mapped.valueAt("/missing", Person.class); + assertThat(person).isNotNull(); assertThat(person.getName().getFirst()).isNull(); assertThat(person.getName().getLast()).isNull(); } @@ -82,6 +84,7 @@ class MappedObjectTests extends AbstractJsonTests { @Test void valueAtWhenDefaultMethodReturnsValue() { Person person = this.mapped.valueAt("/person", Person.class); + assertThat(person).isNotNull(); assertThat(person.getName().getFullName()).isEqualTo("dr spring boot"); }