Browse Source

Add nullability annotations to tests in build-plugin/spring-boot-maven-plugin

See gh-47263
pull/47665/head
Moritz Halbritter 2 months ago
parent
commit
039fd0fa9a
  1. 12
      build-plugin/spring-boot-maven-plugin/build.gradle
  2. 3
      build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AbstractArchiveIntegrationTests.java
  3. 24
      build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java
  4. 7
      build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java
  5. 4
      build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/Versions.java
  6. 22
      build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/WarIntegrationTests.java
  7. 9
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java
  8. 5
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClassPathTests.java
  9. 3
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/CustomLayersProviderTests.java
  10. 9
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java
  11. 88
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DockerTests.java
  12. 5
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java
  13. 3
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java
  14. 5
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/IncludeFilterTests.java
  15. 4
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/JarTypeFilterTests.java
  16. 5
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/MavenBuildOutputTimestampTests.java
  17. 13
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/PropertiesMergingResourceTransformerTests.java
  18. 4
      build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java

12
build-plugin/spring-boot-maven-plugin/build.gradle

@ -194,3 +194,15 @@ tasks.named("generateAntoraPlaybook") { @@ -194,3 +194,15 @@ tasks.named("generateAntoraPlaybook") {
tasks.named("dockerTest").configure {
dependsOn tasks.named("prepareMavenBinaries")
}
tasks.named("compileTestJava") {
options.nullability.checking = "tests"
}
tasks.named("compileIntTestJava") {
options.nullability.checking = "tests"
}
tasks.named("compileDockerTestJava") {
options.nullability.checking = "tests"
}

3
build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/AbstractArchiveIntegrationTests.java

@ -36,6 +36,7 @@ import java.util.zip.ZipEntry; @@ -36,6 +36,7 @@ import java.util.zip.ZipEntry;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AssertProvider;
import org.assertj.core.api.ListAssert;
import org.jspecify.annotations.Nullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.contentOf;
@ -95,7 +96,7 @@ abstract class AbstractArchiveIntegrationTests { @@ -95,7 +96,7 @@ abstract class AbstractArchiveIntegrationTests {
}
}
protected String getLayersIndexLocation() {
protected @Nullable String getLayersIndexLocation() {
return null;
}

24
build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java

@ -29,6 +29,7 @@ import org.junit.jupiter.api.TestTemplate; @@ -29,6 +29,7 @@ import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.loader.tools.JarModeLibrary;
import org.springframework.boot.loader.tools.LibraryCoordinates;
import org.springframework.boot.testsupport.FileUtils;
import org.springframework.util.FileSystemUtils;
@ -389,10 +390,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -389,10 +390,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
void repackagedJarContainsTheLayersIndexByDefault(MavenBuild mavenBuild) {
mavenBuild.project("jar-layered").execute((project) -> {
File repackaged = new File(project, "jar/target/jar-layered-0.0.1.BUILD-SNAPSHOT.jar");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-snapshot")
.hasEntryWithNameStartingWith("BOOT-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId());
.hasEntryWithNameStartingWith("BOOT-INF/lib/" + coordinates.getArtifactId());
try (JarFile jarFile = new JarFile(repackaged)) {
Map<String, List<String>> layerIndex = readLayerIndex(jarFile);
assertThat(layerIndex.keySet()).containsExactly("dependencies", "spring-boot-loader",
@ -412,10 +415,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -412,10 +415,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenJarIsRepackagedWithTheLayersDisabledDoesNotContainLayersIndex(MavenBuild mavenBuild) {
mavenBuild.project("jar-layered-disabled").execute((project) -> {
File repackaged = new File(project, "jar/target/jar-layered-0.0.1.BUILD-SNAPSHOT.jar");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-snapshot")
.hasEntryWithNameStartingWith("BOOT-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId())
.hasEntryWithNameStartingWith("BOOT-INF/lib/" + coordinates.getArtifactId())
.doesNotHaveEntryWithName("BOOT-INF/layers.idx");
});
}
@ -424,11 +429,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -424,11 +429,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenJarIsRepackagedWithToolsExclude(MavenBuild mavenBuild) {
mavenBuild.project("jar-no-tools").execute((project) -> {
File repackaged = new File(project, "jar/target/jar-no-tools-0.0.1.BUILD-SNAPSHOT.jar");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-snapshot")
.doesNotHaveEntryWithNameStartingWith(
"BOOT-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId());
.doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/" + coordinates.getArtifactId());
});
}
@ -496,18 +502,22 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -496,18 +502,22 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
throw new RuntimeException(ex);
}
});
return jarHash.get();
String hash = jarHash.get();
assertThat(hash).isNotNull();
return hash;
}
@TestTemplate
void whenJarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) {
mavenBuild.project("jar-output-timestamp").execute((project) -> {
File repackaged = new File(project, "target/jar-output-timestamp-0.0.1.BUILD-SNAPSHOT.jar");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
List<String> sortedLibs = Arrays.asList("BOOT-INF/lib/commons-logging", "BOOT-INF/lib/jakarta.servlet-api",
"BOOT-INF/lib/jspecify", "BOOT-INF/lib/micrometer-commons", "BOOT-INF/lib/micrometer-observation",
"BOOT-INF/lib/spring-aop", "BOOT-INF/lib/spring-beans",
"BOOT-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId(),
"BOOT-INF/lib/spring-context", "BOOT-INF/lib/spring-core", "BOOT-INF/lib/spring-expression");
"BOOT-INF/lib/" + coordinates.getArtifactId(), "BOOT-INF/lib/spring-context",
"BOOT-INF/lib/spring-core", "BOOT-INF/lib/spring-expression");
assertThat(jar(repackaged)).entryNamesInPath("BOOT-INF/lib/")
.zipSatisfy(sortedLibs,
(String jarLib, String expectedLib) -> assertThat(jarLib).startsWith(expectedLib));

7
build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/MavenBuild.java

@ -43,7 +43,9 @@ import org.apache.maven.shared.invoker.InvocationRequest; @@ -43,7 +43,9 @@ import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.FileSystemUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -67,9 +69,9 @@ class MavenBuild { @@ -67,9 +69,9 @@ class MavenBuild {
private final Properties properties = new Properties();
private ProjectCallback preparation;
private @Nullable ProjectCallback preparation;
private File projectDir;
private @Nullable File projectDir;
MavenBuild(File home) {
this.home = home;
@ -133,6 +135,7 @@ class MavenBuild { @@ -133,6 +135,7 @@ class MavenBuild {
InvocationRequest request = new DefaultInvocationRequest();
try {
Path destination = this.temp.toPath();
Assert.notNull(this.projectDir, "'projectDir' must not be null");
Path source = this.projectDir.toPath();
Files.walkFileTree(source, new SimpleFileVisitor<>() {

4
build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/Versions.java

@ -23,6 +23,8 @@ import java.util.HashMap; @@ -23,6 +23,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.jspecify.annotations.Nullable;
/**
* Provides access to various versions.
*
@ -49,7 +51,7 @@ class Versions { @@ -49,7 +51,7 @@ class Versions {
}
}
String get(String name) {
@Nullable String get(String name) {
return this.versions.get(name);
}

22
build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/WarIntegrationTests.java

@ -30,6 +30,7 @@ import org.junit.jupiter.api.TestTemplate; @@ -30,6 +30,7 @@ import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.loader.tools.JarModeLibrary;
import org.springframework.boot.loader.tools.LibraryCoordinates;
import org.springframework.boot.testsupport.FileUtils;
import org.springframework.util.FileSystemUtils;
@ -113,13 +114,17 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -113,13 +114,17 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
throw new RuntimeException(ex);
}
});
return warHash.get();
String hash = warHash.get();
assertThat(hash).isNotNull();
return hash;
}
@TestTemplate
void whenWarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) {
mavenBuild.project("war-output-timestamp").execute((project) -> {
File repackaged = new File(project, "target/war-output-timestamp-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
List<String> sortedLibs = Arrays.asList(
// these libraries are copied from the original war, sorted when
// packaged by Maven
@ -128,7 +133,7 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -128,7 +133,7 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
"WEB-INF/lib/spring-context", "WEB-INF/lib/spring-core", "WEB-INF/lib/spring-expression",
// these libraries are contributed by Spring Boot repackaging, and
// sorted separately
"WEB-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId());
"WEB-INF/lib/" + coordinates.getArtifactId());
assertThat(jar(repackaged)).entryNamesInPath("WEB-INF/lib/")
.zipSatisfy(sortedLibs,
(String jarLib, String expectedLib) -> assertThat(jarLib).startsWith(expectedLib));
@ -148,10 +153,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -148,10 +153,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
void repackagedWarContainsTheLayersIndexByDefault(MavenBuild mavenBuild) {
mavenBuild.project("war-layered").execute((project) -> {
File repackaged = new File(project, "war/target/war-layered-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot")
.hasEntryWithNameStartingWith("WEB-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId());
.hasEntryWithNameStartingWith("WEB-INF/lib/" + coordinates.getArtifactId());
try (JarFile jarFile = new JarFile(repackaged)) {
Map<String, List<String>> layerIndex = readLayerIndex(jarFile);
assertThat(layerIndex.keySet()).containsExactly("dependencies", "spring-boot-loader",
@ -176,10 +183,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -176,10 +183,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenWarIsRepackagedWithTheLayersDisabledDoesNotContainLayersIndex(MavenBuild mavenBuild) {
mavenBuild.project("war-layered-disabled").execute((project) -> {
File repackaged = new File(project, "war/target/war-layered-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot")
.hasEntryWithNameStartingWith("WEB-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId())
.hasEntryWithNameStartingWith("WEB-INF/lib/" + coordinates.getArtifactId())
.doesNotHaveEntryWithName("WEB-INF/layers.idx");
});
}
@ -188,11 +197,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests { @@ -188,11 +197,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenWarIsRepackagedWithToolsExclude(MavenBuild mavenBuild) {
mavenBuild.project("war-no-tools").execute((project) -> {
File repackaged = new File(project, "war/target/war-no-tools-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot")
.doesNotHaveEntryWithNameStartingWith(
"WEB-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId());
.doesNotHaveEntryWithNameStartingWith("WEB-INF/lib/" + coordinates.getArtifactId());
});
}

9
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ArtifactsLibrariesTests.java

@ -38,6 +38,7 @@ import org.mockito.junit.jupiter.MockitoExtension; @@ -38,6 +38,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.loader.tools.Library;
import org.springframework.boot.loader.tools.LibraryCallback;
import org.springframework.boot.loader.tools.LibraryCoordinates;
import org.springframework.boot.loader.tools.LibraryScope;
import static org.assertj.core.api.Assertions.assertThat;
@ -56,9 +57,11 @@ import static org.mockito.Mockito.times; @@ -56,9 +57,11 @@ import static org.mockito.Mockito.times;
class ArtifactsLibrariesTests {
@Mock
@SuppressWarnings("NullAway.Init")
private Artifact artifact;
@Mock
@SuppressWarnings("NullAway.Init")
private ArtifactHandler artifactHandler;
private Set<Artifact> artifacts;
@ -68,9 +71,11 @@ class ArtifactsLibrariesTests { @@ -68,9 +71,11 @@ class ArtifactsLibrariesTests {
private ArtifactsLibraries libs;
@Mock
@SuppressWarnings("NullAway.Init")
private LibraryCallback callback;
@Captor
@SuppressWarnings("NullAway.Init")
private ArgumentCaptor<Library> libraryCaptor;
@BeforeEach
@ -146,7 +151,9 @@ class ArtifactsLibrariesTests { @@ -146,7 +151,9 @@ class ArtifactsLibrariesTests {
.doWithLibraries((library) -> {
assertThat(library.isIncluded()).isTrue();
assertThat(library.isLocal()).isFalse();
assertThat(library.getCoordinates().getVersion()).isEqualTo("1.0-SNAPSHOT");
LibraryCoordinates coordinates = library.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(coordinates.getVersion()).isEqualTo("1.0-SNAPSHOT");
});
}

5
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ClassPathTests.java

@ -24,6 +24,7 @@ import java.util.List; @@ -24,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.function.UnaryOperator;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -93,11 +94,11 @@ class ClassPathTests { @@ -93,11 +94,11 @@ class ClassPathTests {
assertThat(classPath.toString()).isEqualTo(path1 + File.pathSeparator + path2);
}
private UnaryOperator<String> onWindows() {
private UnaryOperator<@Nullable String> onWindows() {
return Map.of("os.name", "windows")::get;
}
private UnaryOperator<String> onLinux() {
private UnaryOperator<@Nullable String> onLinux() {
return Map.of("os.name", "linux")::get;
}

3
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/CustomLayersProviderTests.java

@ -19,6 +19,7 @@ package org.springframework.boot.maven; @@ -19,6 +19,7 @@ package org.springframework.boot.maven;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
@ -69,7 +70,7 @@ class CustomLayersProviderTests { @@ -69,7 +70,7 @@ class CustomLayersProviderTests {
assertThat(layers.getLayer("test")).hasToString("application");
}
private Library mockLibrary(String name, String groupId, String version) {
private Library mockLibrary(String name, String groupId, @Nullable String version) {
Library library = mock(Library.class);
given(library.getName()).willReturn(name);
given(library.getCoordinates()).willReturn(LibraryCoordinates.of(groupId, null, version));

9
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java

@ -33,6 +33,7 @@ import org.apache.maven.artifact.Artifact; @@ -33,6 +33,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
import org.apache.maven.shared.artifact.filter.collection.ScopeFilter;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -48,6 +49,7 @@ import static org.mockito.Mockito.mock; @@ -48,6 +49,7 @@ import static org.mockito.Mockito.mock;
class DependencyFilterMojoTests {
@TempDir
@SuppressWarnings("NullAway.Init")
static Path temp;
@Test
@ -121,11 +123,12 @@ class DependencyFilterMojoTests { @@ -121,11 +123,12 @@ class DependencyFilterMojoTests {
return createArtifact(groupId, artifactId, null);
}
private static Artifact createArtifact(String groupId, String artifactId, String scope) {
private static Artifact createArtifact(String groupId, String artifactId, @Nullable String scope) {
return createArtifact(groupId, artifactId, scope, null);
}
private static Artifact createArtifact(String groupId, String artifactId, String scope, String jarType) {
private static Artifact createArtifact(String groupId, String artifactId, @Nullable String scope,
@Nullable String jarType) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);
@ -136,7 +139,7 @@ class DependencyFilterMojoTests { @@ -136,7 +139,7 @@ class DependencyFilterMojoTests {
return a;
}
private static File createArtifactFile(String jarType) {
private static File createArtifactFile(@Nullable String jarType) {
Path jarPath = temp.resolve(UUID.randomUUID() + ".jar");
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");

88
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DockerTests.java

@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test; @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.buildpack.platform.build.BuilderDockerConfiguration;
import org.springframework.boot.buildpack.platform.docker.configuration.DockerConnectionConfiguration;
import org.springframework.boot.buildpack.platform.docker.configuration.DockerRegistryAuthentication;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@ -43,9 +44,16 @@ class DockerTests { @@ -43,9 +44,16 @@ class DockerTests {
Docker docker = new Docker();
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
assertThat(dockerConfiguration.connection()).isNull();
assertThat(dockerConfiguration.builderRegistryAuthentication().getAuthHeader()).isNull();
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader()))
.contains("\"username\" : \"\"")
DockerRegistryAuthentication builderRegistryAuthentication = dockerConfiguration
.builderRegistryAuthentication();
assertThat(builderRegistryAuthentication).isNotNull();
assertThat(builderRegistryAuthentication.getAuthHeader()).isNull();
DockerRegistryAuthentication publishRegistryAuthentication = dockerConfiguration
.publishRegistryAuthentication();
assertThat(publishRegistryAuthentication).isNotNull();
String authHeader = publishRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"\"")
.contains("\"password\" : \"\"")
.contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\"");
@ -59,13 +67,21 @@ class DockerTests { @@ -59,13 +67,21 @@ class DockerTests {
docker.setCertPath("/tmp/ca-cert");
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
DockerConnectionConfiguration.Host host = (DockerConnectionConfiguration.Host) dockerConfiguration.connection();
assertThat(host).isNotNull();
assertThat(host.address()).isEqualTo("docker.example.com");
assertThat(host.secure()).isTrue();
assertThat(host.certificatePath()).isEqualTo("/tmp/ca-cert");
assertThat(dockerConfiguration.bindHostToBuilder()).isFalse();
assertThat(createDockerConfiguration(docker).builderRegistryAuthentication().getAuthHeader()).isNull();
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader()))
.contains("\"username\" : \"\"")
DockerRegistryAuthentication builderRegistryAuthentication = createDockerConfiguration(docker)
.builderRegistryAuthentication();
assertThat(builderRegistryAuthentication).isNotNull();
assertThat(builderRegistryAuthentication.getAuthHeader()).isNull();
DockerRegistryAuthentication publishRegistryAuthentication = dockerConfiguration
.publishRegistryAuthentication();
assertThat(publishRegistryAuthentication).isNotNull();
String authHeader = publishRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"\"")
.contains("\"password\" : \"\"")
.contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\"");
@ -78,11 +94,19 @@ class DockerTests { @@ -78,11 +94,19 @@ class DockerTests {
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
DockerConnectionConfiguration.Context context = (DockerConnectionConfiguration.Context) dockerConfiguration
.connection();
assertThat(context).isNotNull();
assertThat(context.context()).isEqualTo("test-context");
assertThat(dockerConfiguration.bindHostToBuilder()).isFalse();
assertThat(createDockerConfiguration(docker).builderRegistryAuthentication().getAuthHeader()).isNull();
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader()))
.contains("\"username\" : \"\"")
DockerRegistryAuthentication builderRegistryAuthentication = createDockerConfiguration(docker)
.builderRegistryAuthentication();
assertThat(builderRegistryAuthentication).isNotNull();
assertThat(builderRegistryAuthentication.getAuthHeader()).isNull();
DockerRegistryAuthentication publishRegistryAuthentication = dockerConfiguration
.publishRegistryAuthentication();
assertThat(publishRegistryAuthentication).isNotNull();
String authHeader = publishRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"\"")
.contains("\"password\" : \"\"")
.contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\"");
@ -106,13 +130,21 @@ class DockerTests { @@ -106,13 +130,21 @@ class DockerTests {
docker.setBindHostToBuilder(true);
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
DockerConnectionConfiguration.Host host = (DockerConnectionConfiguration.Host) dockerConfiguration.connection();
assertThat(host).isNotNull();
assertThat(host.address()).isEqualTo("docker.example.com");
assertThat(host.secure()).isTrue();
assertThat(host.certificatePath()).isEqualTo("/tmp/ca-cert");
assertThat(dockerConfiguration.bindHostToBuilder()).isTrue();
assertThat(createDockerConfiguration(docker).builderRegistryAuthentication().getAuthHeader()).isNull();
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader()))
.contains("\"username\" : \"\"")
DockerRegistryAuthentication builderRegistryAuthentication = createDockerConfiguration(docker)
.builderRegistryAuthentication();
assertThat(builderRegistryAuthentication).isNotNull();
assertThat(builderRegistryAuthentication.getAuthHeader()).isNull();
DockerRegistryAuthentication publishRegistryAuthentication = dockerConfiguration
.publishRegistryAuthentication();
assertThat(publishRegistryAuthentication).isNotNull();
String authHeader = publishRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"\"")
.contains("\"password\" : \"\"")
.contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\"");
@ -126,13 +158,21 @@ class DockerTests { @@ -126,13 +158,21 @@ class DockerTests {
docker.setPublishRegistry(
new Docker.DockerRegistry("user2", "secret2", "https://docker2.example.com", "docker2@example.com"));
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
assertThat(decoded(dockerConfiguration.builderRegistryAuthentication().getAuthHeader()))
.contains("\"username\" : \"user1\"")
DockerRegistryAuthentication builderRegistryAuthentication = dockerConfiguration
.builderRegistryAuthentication();
assertThat(builderRegistryAuthentication).isNotNull();
String authHeader = builderRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"user1\"")
.contains("\"password\" : \"secret1\"")
.contains("\"email\" : \"docker1@example.com\"")
.contains("\"serveraddress\" : \"https://docker1.example.com\"");
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader()))
.contains("\"username\" : \"user2\"")
DockerRegistryAuthentication publishRegistryAuthentication = dockerConfiguration
.publishRegistryAuthentication();
assertThat(publishRegistryAuthentication).isNotNull();
authHeader = publishRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"user2\"")
.contains("\"password\" : \"secret2\"")
.contains("\"email\" : \"docker2@example.com\"")
.contains("\"serveraddress\" : \"https://docker2.example.com\"");
@ -171,10 +211,18 @@ class DockerTests { @@ -171,10 +211,18 @@ class DockerTests {
docker.setBuilderRegistry(new Docker.DockerRegistry("token1"));
docker.setPublishRegistry(new Docker.DockerRegistry("token2"));
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
assertThat(decoded(dockerConfiguration.builderRegistryAuthentication().getAuthHeader()))
.contains("\"identitytoken\" : \"token1\"");
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader()))
.contains("\"identitytoken\" : \"token2\"");
DockerRegistryAuthentication builderRegistryAuthentication = dockerConfiguration
.builderRegistryAuthentication();
assertThat(builderRegistryAuthentication).isNotNull();
String authHeader = builderRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"identitytoken\" : \"token1\"");
DockerRegistryAuthentication publishRegistryAuthentication = dockerConfiguration
.publishRegistryAuthentication();
assertThat(publishRegistryAuthentication).isNotNull();
authHeader = publishRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"identitytoken\" : \"token2\"");
}
@Test

5
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ExcludeFilterTests.java

@ -23,6 +23,7 @@ import java.util.Set; @@ -23,6 +23,7 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -106,7 +107,7 @@ class ExcludeFilterTests { @@ -106,7 +107,7 @@ class ExcludeFilterTests {
return createExclude(groupId, artifactId, null);
}
private Exclude createExclude(String groupId, String artifactId, String classifier) {
private Exclude createExclude(String groupId, String artifactId, @Nullable String classifier) {
Exclude exclude = new Exclude();
exclude.setGroupId(groupId);
exclude.setArtifactId(artifactId);
@ -116,7 +117,7 @@ class ExcludeFilterTests { @@ -116,7 +117,7 @@ class ExcludeFilterTests {
return exclude;
}
private Artifact createArtifact(String groupId, String artifactId, String classifier) {
private Artifact createArtifact(String groupId, String artifactId, @Nullable String classifier) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);

3
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java

@ -41,6 +41,7 @@ import org.springframework.boot.maven.CacheInfo.VolumeCacheInfo; @@ -41,6 +41,7 @@ import org.springframework.boot.maven.CacheInfo.VolumeCacheInfo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link Image}.
@ -305,7 +306,7 @@ class ImageTests { @@ -305,7 +306,7 @@ class ImageTests {
}
private Function<Owner, TarArchive> mockApplicationContent() {
return (owner) -> null;
return (owner) -> mock(TarArchive.class);
}
}

5
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/IncludeFilterTests.java

@ -23,6 +23,7 @@ import java.util.Set; @@ -23,6 +23,7 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -104,7 +105,7 @@ class IncludeFilterTests { @@ -104,7 +105,7 @@ class IncludeFilterTests {
return createInclude(groupId, artifactId, null);
}
private Include createInclude(String groupId, String artifactId, String classifier) {
private Include createInclude(String groupId, String artifactId, @Nullable String classifier) {
Include include = new Include();
include.setGroupId(groupId);
include.setArtifactId(artifactId);
@ -114,7 +115,7 @@ class IncludeFilterTests { @@ -114,7 +115,7 @@ class IncludeFilterTests {
return include;
}
private Artifact createArtifact(String groupId, String artifactId, String classifier) {
private Artifact createArtifact(String groupId, String artifactId, @Nullable String classifier) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);

4
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/JarTypeFilterTests.java

@ -23,6 +23,7 @@ import java.util.jar.JarOutputStream; @@ -23,6 +23,7 @@ import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
import org.apache.maven.artifact.Artifact;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@ -38,6 +39,7 @@ import static org.mockito.Mockito.mock; @@ -38,6 +39,7 @@ import static org.mockito.Mockito.mock;
class JarTypeFilterTests {
@TempDir
@SuppressWarnings("NullAway.Init")
Path temp;
@Test
@ -70,7 +72,7 @@ class JarTypeFilterTests { @@ -70,7 +72,7 @@ class JarTypeFilterTests {
assertThat(new JarTypeFilter().filter(createArtifactWithNoManifest())).isFalse();
}
private Artifact createArtifact(String springBootJarType) {
private Artifact createArtifact(@Nullable String springBootJarType) {
Path jarPath = this.temp.resolve("test.jar");
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");

5
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/MavenBuildOutputTimestampTests.java

@ -19,6 +19,7 @@ package org.springframework.boot.maven; @@ -19,6 +19,7 @@ package org.springframework.boot.maven;
import java.nio.file.attribute.FileTime;
import java.time.Instant;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -88,11 +89,11 @@ class MavenBuildOutputTimestampTests { @@ -88,11 +89,11 @@ class MavenBuildOutputTimestampTests {
assertThat(parseFileTime("2019-10-05T14:37:42Z")).isEqualTo(FileTime.fromMillis(1570286262000L));
}
private static Instant parse(String timestamp) {
private static @Nullable Instant parse(@Nullable String timestamp) {
return new MavenBuildOutputTimestamp(timestamp).toInstant();
}
private static FileTime parseFileTime(String timestamp) {
private static @Nullable FileTime parseFileTime(@Nullable String timestamp) {
return new MavenBuildOutputTimestamp(timestamp).toFileTime();
}

13
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/PropertiesMergingResourceTransformerTests.java

@ -19,6 +19,7 @@ package org.springframework.boot.maven; @@ -19,6 +19,7 @@ package org.springframework.boot.maven;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarInputStream;
@ -40,14 +41,17 @@ class PropertiesMergingResourceTransformerTests { @@ -40,14 +41,17 @@ class PropertiesMergingResourceTransformerTests {
@Test
void testProcess() throws Exception {
assertThat(this.transformer.hasTransformedResource()).isFalse();
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, 0);
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), Collections.emptyList(),
0);
assertThat(this.transformer.hasTransformedResource()).isTrue();
}
@Test
void testMerge() throws Exception {
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, 0);
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()), null, 0);
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), Collections.emptyList(),
0);
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()),
Collections.emptyList(), 0);
assertThat(this.transformer.getData().getProperty("foo")).isEqualTo("bar,spam");
}
@ -55,7 +59,8 @@ class PropertiesMergingResourceTransformerTests { @@ -55,7 +59,8 @@ class PropertiesMergingResourceTransformerTests {
void testOutput() throws Exception {
this.transformer.setResource("foo");
long time = 1592911068000L;
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, time);
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), Collections.emptyList(),
time);
ByteArrayOutputStream out = new ByteArrayOutputStream();
JarOutputStream os = new JarOutputStream(out);
this.transformer.modifyOutputStream(os);

4
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/RunArgumentsTests.java

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.boot.maven;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -35,6 +36,7 @@ class RunArgumentsTests { @@ -35,6 +36,7 @@ class RunArgumentsTests {
}
@Test
@SuppressWarnings("NullAway") // Maven can't handle nullable arrays
void parseNullArray() {
String[] args = new RunArguments((String[]) null).asArray();
assertThat(args).isNotNull();
@ -92,7 +94,7 @@ class RunArgumentsTests { @@ -92,7 +94,7 @@ class RunArgumentsTests {
assertThat(args[0]).isEqualTo("-Dvalue=My Value");
}
private String[] parseArgs(String args) {
private String[] parseArgs(@Nullable String args) {
return new RunArguments(args).asArray();
}

Loading…
Cancel
Save