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") {
tasks.named("dockerTest").configure { tasks.named("dockerTest").configure {
dependsOn tasks.named("prepareMavenBinaries") 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;
import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AssertProvider; import org.assertj.core.api.AssertProvider;
import org.assertj.core.api.ListAssert; 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.assertThat;
import static org.assertj.core.api.Assertions.contentOf; import static org.assertj.core.api.Assertions.contentOf;
@ -95,7 +96,7 @@ abstract class AbstractArchiveIntegrationTests {
} }
} }
protected String getLayersIndexLocation() { protected @Nullable String getLayersIndexLocation() {
return null; 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;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.loader.tools.JarModeLibrary; import org.springframework.boot.loader.tools.JarModeLibrary;
import org.springframework.boot.loader.tools.LibraryCoordinates;
import org.springframework.boot.testsupport.FileUtils; import org.springframework.boot.testsupport.FileUtils;
import org.springframework.util.FileSystemUtils; import org.springframework.util.FileSystemUtils;
@ -389,10 +390,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
void repackagedJarContainsTheLayersIndexByDefault(MavenBuild mavenBuild) { void repackagedJarContainsTheLayersIndexByDefault(MavenBuild mavenBuild) {
mavenBuild.project("jar-layered").execute((project) -> { mavenBuild.project("jar-layered").execute((project) -> {
File repackaged = new File(project, "jar/target/jar-layered-0.0.1.BUILD-SNAPSHOT.jar"); 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/") assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release") .hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-snapshot") .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)) { try (JarFile jarFile = new JarFile(repackaged)) {
Map<String, List<String>> layerIndex = readLayerIndex(jarFile); Map<String, List<String>> layerIndex = readLayerIndex(jarFile);
assertThat(layerIndex.keySet()).containsExactly("dependencies", "spring-boot-loader", assertThat(layerIndex.keySet()).containsExactly("dependencies", "spring-boot-loader",
@ -412,10 +415,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenJarIsRepackagedWithTheLayersDisabledDoesNotContainLayersIndex(MavenBuild mavenBuild) { void whenJarIsRepackagedWithTheLayersDisabledDoesNotContainLayersIndex(MavenBuild mavenBuild) {
mavenBuild.project("jar-layered-disabled").execute((project) -> { mavenBuild.project("jar-layered-disabled").execute((project) -> {
File repackaged = new File(project, "jar/target/jar-layered-0.0.1.BUILD-SNAPSHOT.jar"); 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/") assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release") .hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-snapshot") .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"); .doesNotHaveEntryWithName("BOOT-INF/layers.idx");
}); });
} }
@ -424,11 +429,12 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenJarIsRepackagedWithToolsExclude(MavenBuild mavenBuild) { void whenJarIsRepackagedWithToolsExclude(MavenBuild mavenBuild) {
mavenBuild.project("jar-no-tools").execute((project) -> { mavenBuild.project("jar-no-tools").execute((project) -> {
File repackaged = new File(project, "jar/target/jar-no-tools-0.0.1.BUILD-SNAPSHOT.jar"); 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/") assertThat(jar(repackaged)).hasEntryWithNameStartingWith("BOOT-INF/classes/")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release") .hasEntryWithNameStartingWith("BOOT-INF/lib/jar-release")
.hasEntryWithNameStartingWith("BOOT-INF/lib/jar-snapshot") .hasEntryWithNameStartingWith("BOOT-INF/lib/jar-snapshot")
.doesNotHaveEntryWithNameStartingWith( .doesNotHaveEntryWithNameStartingWith("BOOT-INF/lib/" + coordinates.getArtifactId());
"BOOT-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId());
}); });
} }
@ -496,18 +502,22 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
}); });
return jarHash.get(); String hash = jarHash.get();
assertThat(hash).isNotNull();
return hash;
} }
@TestTemplate @TestTemplate
void whenJarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) { void whenJarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) {
mavenBuild.project("jar-output-timestamp").execute((project) -> { mavenBuild.project("jar-output-timestamp").execute((project) -> {
File repackaged = new File(project, "target/jar-output-timestamp-0.0.1.BUILD-SNAPSHOT.jar"); 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", 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/jspecify", "BOOT-INF/lib/micrometer-commons", "BOOT-INF/lib/micrometer-observation",
"BOOT-INF/lib/spring-aop", "BOOT-INF/lib/spring-beans", "BOOT-INF/lib/spring-aop", "BOOT-INF/lib/spring-beans",
"BOOT-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId(), "BOOT-INF/lib/" + coordinates.getArtifactId(), "BOOT-INF/lib/spring-context",
"BOOT-INF/lib/spring-context", "BOOT-INF/lib/spring-core", "BOOT-INF/lib/spring-expression"); "BOOT-INF/lib/spring-core", "BOOT-INF/lib/spring-expression");
assertThat(jar(repackaged)).entryNamesInPath("BOOT-INF/lib/") assertThat(jar(repackaged)).entryNamesInPath("BOOT-INF/lib/")
.zipSatisfy(sortedLibs, .zipSatisfy(sortedLibs,
(String jarLib, String expectedLib) -> assertThat(jarLib).startsWith(expectedLib)); (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;
import org.apache.maven.shared.invoker.InvocationResult; import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker; import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenInvocationException; import org.apache.maven.shared.invoker.MavenInvocationException;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.FileSystemUtils; import org.springframework.util.FileSystemUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -67,9 +69,9 @@ class MavenBuild {
private final Properties properties = new Properties(); private final Properties properties = new Properties();
private ProjectCallback preparation; private @Nullable ProjectCallback preparation;
private File projectDir; private @Nullable File projectDir;
MavenBuild(File home) { MavenBuild(File home) {
this.home = home; this.home = home;
@ -133,6 +135,7 @@ class MavenBuild {
InvocationRequest request = new DefaultInvocationRequest(); InvocationRequest request = new DefaultInvocationRequest();
try { try {
Path destination = this.temp.toPath(); Path destination = this.temp.toPath();
Assert.notNull(this.projectDir, "'projectDir' must not be null");
Path source = this.projectDir.toPath(); Path source = this.projectDir.toPath();
Files.walkFileTree(source, new SimpleFileVisitor<>() { 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;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.jspecify.annotations.Nullable;
/** /**
* Provides access to various versions. * Provides access to various versions.
* *
@ -49,7 +51,7 @@ class Versions {
} }
} }
String get(String name) { @Nullable String get(String name) {
return this.versions.get(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;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.loader.tools.JarModeLibrary; import org.springframework.boot.loader.tools.JarModeLibrary;
import org.springframework.boot.loader.tools.LibraryCoordinates;
import org.springframework.boot.testsupport.FileUtils; import org.springframework.boot.testsupport.FileUtils;
import org.springframework.util.FileSystemUtils; import org.springframework.util.FileSystemUtils;
@ -113,13 +114,17 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
}); });
return warHash.get(); String hash = warHash.get();
assertThat(hash).isNotNull();
return hash;
} }
@TestTemplate @TestTemplate
void whenWarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) { void whenWarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) {
mavenBuild.project("war-output-timestamp").execute((project) -> { mavenBuild.project("war-output-timestamp").execute((project) -> {
File repackaged = new File(project, "target/war-output-timestamp-0.0.1.BUILD-SNAPSHOT.war"); 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( List<String> sortedLibs = Arrays.asList(
// these libraries are copied from the original war, sorted when // these libraries are copied from the original war, sorted when
// packaged by Maven // packaged by Maven
@ -128,7 +133,7 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
"WEB-INF/lib/spring-context", "WEB-INF/lib/spring-core", "WEB-INF/lib/spring-expression", "WEB-INF/lib/spring-context", "WEB-INF/lib/spring-core", "WEB-INF/lib/spring-expression",
// these libraries are contributed by Spring Boot repackaging, and // these libraries are contributed by Spring Boot repackaging, and
// sorted separately // sorted separately
"WEB-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().getArtifactId()); "WEB-INF/lib/" + coordinates.getArtifactId());
assertThat(jar(repackaged)).entryNamesInPath("WEB-INF/lib/") assertThat(jar(repackaged)).entryNamesInPath("WEB-INF/lib/")
.zipSatisfy(sortedLibs, .zipSatisfy(sortedLibs,
(String jarLib, String expectedLib) -> assertThat(jarLib).startsWith(expectedLib)); (String jarLib, String expectedLib) -> assertThat(jarLib).startsWith(expectedLib));
@ -148,10 +153,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
void repackagedWarContainsTheLayersIndexByDefault(MavenBuild mavenBuild) { void repackagedWarContainsTheLayersIndexByDefault(MavenBuild mavenBuild) {
mavenBuild.project("war-layered").execute((project) -> { mavenBuild.project("war-layered").execute((project) -> {
File repackaged = new File(project, "war/target/war-layered-0.0.1.BUILD-SNAPSHOT.war"); 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/") assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release") .hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot") .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)) { try (JarFile jarFile = new JarFile(repackaged)) {
Map<String, List<String>> layerIndex = readLayerIndex(jarFile); Map<String, List<String>> layerIndex = readLayerIndex(jarFile);
assertThat(layerIndex.keySet()).containsExactly("dependencies", "spring-boot-loader", assertThat(layerIndex.keySet()).containsExactly("dependencies", "spring-boot-loader",
@ -176,10 +183,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenWarIsRepackagedWithTheLayersDisabledDoesNotContainLayersIndex(MavenBuild mavenBuild) { void whenWarIsRepackagedWithTheLayersDisabledDoesNotContainLayersIndex(MavenBuild mavenBuild) {
mavenBuild.project("war-layered-disabled").execute((project) -> { mavenBuild.project("war-layered-disabled").execute((project) -> {
File repackaged = new File(project, "war/target/war-layered-0.0.1.BUILD-SNAPSHOT.war"); 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/") assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release") .hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot") .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"); .doesNotHaveEntryWithName("WEB-INF/layers.idx");
}); });
} }
@ -188,11 +197,12 @@ class WarIntegrationTests extends AbstractArchiveIntegrationTests {
void whenWarIsRepackagedWithToolsExclude(MavenBuild mavenBuild) { void whenWarIsRepackagedWithToolsExclude(MavenBuild mavenBuild) {
mavenBuild.project("war-no-tools").execute((project) -> { mavenBuild.project("war-no-tools").execute((project) -> {
File repackaged = new File(project, "war/target/war-no-tools-0.0.1.BUILD-SNAPSHOT.war"); 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/") assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release") .hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot") .hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot")
.doesNotHaveEntryWithNameStartingWith( .doesNotHaveEntryWithNameStartingWith("WEB-INF/lib/" + coordinates.getArtifactId());
"WEB-INF/lib/" + JarModeLibrary.TOOLS.getCoordinates().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;
import org.springframework.boot.loader.tools.Library; import org.springframework.boot.loader.tools.Library;
import org.springframework.boot.loader.tools.LibraryCallback; import org.springframework.boot.loader.tools.LibraryCallback;
import org.springframework.boot.loader.tools.LibraryCoordinates;
import org.springframework.boot.loader.tools.LibraryScope; import org.springframework.boot.loader.tools.LibraryScope;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -56,9 +57,11 @@ import static org.mockito.Mockito.times;
class ArtifactsLibrariesTests { class ArtifactsLibrariesTests {
@Mock @Mock
@SuppressWarnings("NullAway.Init")
private Artifact artifact; private Artifact artifact;
@Mock @Mock
@SuppressWarnings("NullAway.Init")
private ArtifactHandler artifactHandler; private ArtifactHandler artifactHandler;
private Set<Artifact> artifacts; private Set<Artifact> artifacts;
@ -68,9 +71,11 @@ class ArtifactsLibrariesTests {
private ArtifactsLibraries libs; private ArtifactsLibraries libs;
@Mock @Mock
@SuppressWarnings("NullAway.Init")
private LibraryCallback callback; private LibraryCallback callback;
@Captor @Captor
@SuppressWarnings("NullAway.Init")
private ArgumentCaptor<Library> libraryCaptor; private ArgumentCaptor<Library> libraryCaptor;
@BeforeEach @BeforeEach
@ -146,7 +151,9 @@ class ArtifactsLibrariesTests {
.doWithLibraries((library) -> { .doWithLibraries((library) -> {
assertThat(library.isIncluded()).isTrue(); assertThat(library.isIncluded()).isTrue();
assertThat(library.isLocal()).isFalse(); 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;
import java.util.Map; import java.util.Map;
import java.util.function.UnaryOperator; import java.util.function.UnaryOperator;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.api.io.TempDir;
@ -93,11 +94,11 @@ class ClassPathTests {
assertThat(classPath.toString()).isEqualTo(path1 + File.pathSeparator + path2); assertThat(classPath.toString()).isEqualTo(path1 + File.pathSeparator + path2);
} }
private UnaryOperator<String> onWindows() { private UnaryOperator<@Nullable String> onWindows() {
return Map.of("os.name", "windows")::get; return Map.of("os.name", "windows")::get;
} }
private UnaryOperator<String> onLinux() { private UnaryOperator<@Nullable String> onLinux() {
return Map.of("os.name", "linux")::get; 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;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -69,7 +70,7 @@ class CustomLayersProviderTests {
assertThat(layers.getLayer("test")).hasToString("application"); 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); Library library = mock(Library.class);
given(library.getName()).willReturn(name); given(library.getName()).willReturn(name);
given(library.getCoordinates()).willReturn(LibraryCoordinates.of(groupId, null, version)); 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;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter; import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
import org.apache.maven.shared.artifact.filter.collection.ScopeFilter; 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.Test;
import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.api.io.TempDir;
@ -48,6 +49,7 @@ import static org.mockito.Mockito.mock;
class DependencyFilterMojoTests { class DependencyFilterMojoTests {
@TempDir @TempDir
@SuppressWarnings("NullAway.Init")
static Path temp; static Path temp;
@Test @Test
@ -121,11 +123,12 @@ class DependencyFilterMojoTests {
return createArtifact(groupId, artifactId, null); 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); 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); Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId); given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId); given(a.getArtifactId()).willReturn(artifactId);
@ -136,7 +139,7 @@ class DependencyFilterMojoTests {
return a; return a;
} }
private static File createArtifactFile(String jarType) { private static File createArtifactFile(@Nullable String jarType) {
Path jarPath = temp.resolve(UUID.randomUUID() + ".jar"); Path jarPath = temp.resolve(UUID.randomUUID() + ".jar");
Manifest manifest = new Manifest(); Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); 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;
import org.springframework.boot.buildpack.platform.build.BuilderDockerConfiguration; 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.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.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@ -43,9 +44,16 @@ class DockerTests {
Docker docker = new Docker(); Docker docker = new Docker();
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker); BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
assertThat(dockerConfiguration.connection()).isNull(); assertThat(dockerConfiguration.connection()).isNull();
assertThat(dockerConfiguration.builderRegistryAuthentication().getAuthHeader()).isNull(); DockerRegistryAuthentication builderRegistryAuthentication = dockerConfiguration
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader())) .builderRegistryAuthentication();
.contains("\"username\" : \"\"") 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("\"password\" : \"\"")
.contains("\"email\" : \"\"") .contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\""); .contains("\"serveraddress\" : \"\"");
@ -59,13 +67,21 @@ class DockerTests {
docker.setCertPath("/tmp/ca-cert"); docker.setCertPath("/tmp/ca-cert");
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker); BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
DockerConnectionConfiguration.Host host = (DockerConnectionConfiguration.Host) dockerConfiguration.connection(); DockerConnectionConfiguration.Host host = (DockerConnectionConfiguration.Host) dockerConfiguration.connection();
assertThat(host).isNotNull();
assertThat(host.address()).isEqualTo("docker.example.com"); assertThat(host.address()).isEqualTo("docker.example.com");
assertThat(host.secure()).isTrue(); assertThat(host.secure()).isTrue();
assertThat(host.certificatePath()).isEqualTo("/tmp/ca-cert"); assertThat(host.certificatePath()).isEqualTo("/tmp/ca-cert");
assertThat(dockerConfiguration.bindHostToBuilder()).isFalse(); assertThat(dockerConfiguration.bindHostToBuilder()).isFalse();
assertThat(createDockerConfiguration(docker).builderRegistryAuthentication().getAuthHeader()).isNull(); DockerRegistryAuthentication builderRegistryAuthentication = createDockerConfiguration(docker)
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader())) .builderRegistryAuthentication();
.contains("\"username\" : \"\"") 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("\"password\" : \"\"")
.contains("\"email\" : \"\"") .contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\""); .contains("\"serveraddress\" : \"\"");
@ -78,11 +94,19 @@ class DockerTests {
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker); BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
DockerConnectionConfiguration.Context context = (DockerConnectionConfiguration.Context) dockerConfiguration DockerConnectionConfiguration.Context context = (DockerConnectionConfiguration.Context) dockerConfiguration
.connection(); .connection();
assertThat(context).isNotNull();
assertThat(context.context()).isEqualTo("test-context"); assertThat(context.context()).isEqualTo("test-context");
assertThat(dockerConfiguration.bindHostToBuilder()).isFalse(); assertThat(dockerConfiguration.bindHostToBuilder()).isFalse();
assertThat(createDockerConfiguration(docker).builderRegistryAuthentication().getAuthHeader()).isNull(); DockerRegistryAuthentication builderRegistryAuthentication = createDockerConfiguration(docker)
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader())) .builderRegistryAuthentication();
.contains("\"username\" : \"\"") 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("\"password\" : \"\"")
.contains("\"email\" : \"\"") .contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\""); .contains("\"serveraddress\" : \"\"");
@ -106,13 +130,21 @@ class DockerTests {
docker.setBindHostToBuilder(true); docker.setBindHostToBuilder(true);
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker); BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
DockerConnectionConfiguration.Host host = (DockerConnectionConfiguration.Host) dockerConfiguration.connection(); DockerConnectionConfiguration.Host host = (DockerConnectionConfiguration.Host) dockerConfiguration.connection();
assertThat(host).isNotNull();
assertThat(host.address()).isEqualTo("docker.example.com"); assertThat(host.address()).isEqualTo("docker.example.com");
assertThat(host.secure()).isTrue(); assertThat(host.secure()).isTrue();
assertThat(host.certificatePath()).isEqualTo("/tmp/ca-cert"); assertThat(host.certificatePath()).isEqualTo("/tmp/ca-cert");
assertThat(dockerConfiguration.bindHostToBuilder()).isTrue(); assertThat(dockerConfiguration.bindHostToBuilder()).isTrue();
assertThat(createDockerConfiguration(docker).builderRegistryAuthentication().getAuthHeader()).isNull(); DockerRegistryAuthentication builderRegistryAuthentication = createDockerConfiguration(docker)
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader())) .builderRegistryAuthentication();
.contains("\"username\" : \"\"") 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("\"password\" : \"\"")
.contains("\"email\" : \"\"") .contains("\"email\" : \"\"")
.contains("\"serveraddress\" : \"\""); .contains("\"serveraddress\" : \"\"");
@ -126,13 +158,21 @@ class DockerTests {
docker.setPublishRegistry( docker.setPublishRegistry(
new Docker.DockerRegistry("user2", "secret2", "https://docker2.example.com", "docker2@example.com")); new Docker.DockerRegistry("user2", "secret2", "https://docker2.example.com", "docker2@example.com"));
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker); BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
assertThat(decoded(dockerConfiguration.builderRegistryAuthentication().getAuthHeader())) DockerRegistryAuthentication builderRegistryAuthentication = dockerConfiguration
.contains("\"username\" : \"user1\"") .builderRegistryAuthentication();
assertThat(builderRegistryAuthentication).isNotNull();
String authHeader = builderRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"user1\"")
.contains("\"password\" : \"secret1\"") .contains("\"password\" : \"secret1\"")
.contains("\"email\" : \"docker1@example.com\"") .contains("\"email\" : \"docker1@example.com\"")
.contains("\"serveraddress\" : \"https://docker1.example.com\""); .contains("\"serveraddress\" : \"https://docker1.example.com\"");
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader())) DockerRegistryAuthentication publishRegistryAuthentication = dockerConfiguration
.contains("\"username\" : \"user2\"") .publishRegistryAuthentication();
assertThat(publishRegistryAuthentication).isNotNull();
authHeader = publishRegistryAuthentication.getAuthHeader();
assertThat(authHeader).isNotNull();
assertThat(decoded(authHeader)).contains("\"username\" : \"user2\"")
.contains("\"password\" : \"secret2\"") .contains("\"password\" : \"secret2\"")
.contains("\"email\" : \"docker2@example.com\"") .contains("\"email\" : \"docker2@example.com\"")
.contains("\"serveraddress\" : \"https://docker2.example.com\""); .contains("\"serveraddress\" : \"https://docker2.example.com\"");
@ -171,10 +211,18 @@ class DockerTests {
docker.setBuilderRegistry(new Docker.DockerRegistry("token1")); docker.setBuilderRegistry(new Docker.DockerRegistry("token1"));
docker.setPublishRegistry(new Docker.DockerRegistry("token2")); docker.setPublishRegistry(new Docker.DockerRegistry("token2"));
BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker); BuilderDockerConfiguration dockerConfiguration = createDockerConfiguration(docker);
assertThat(decoded(dockerConfiguration.builderRegistryAuthentication().getAuthHeader())) DockerRegistryAuthentication builderRegistryAuthentication = dockerConfiguration
.contains("\"identitytoken\" : \"token1\""); .builderRegistryAuthentication();
assertThat(decoded(dockerConfiguration.publishRegistryAuthentication().getAuthHeader())) assertThat(builderRegistryAuthentication).isNotNull();
.contains("\"identitytoken\" : \"token2\""); 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 @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;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -106,7 +107,7 @@ class ExcludeFilterTests {
return createExclude(groupId, artifactId, null); 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 exclude = new Exclude();
exclude.setGroupId(groupId); exclude.setGroupId(groupId);
exclude.setArtifactId(artifactId); exclude.setArtifactId(artifactId);
@ -116,7 +117,7 @@ class ExcludeFilterTests {
return exclude; 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); Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId); given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId); 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;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry; import static org.assertj.core.api.Assertions.entry;
import static org.mockito.Mockito.mock;
/** /**
* Tests for {@link Image}. * Tests for {@link Image}.
@ -305,7 +306,7 @@ class ImageTests {
} }
private Function<Owner, TarArchive> mockApplicationContent() { 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;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -104,7 +105,7 @@ class IncludeFilterTests {
return createInclude(groupId, artifactId, null); 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 include = new Include();
include.setGroupId(groupId); include.setGroupId(groupId);
include.setArtifactId(artifactId); include.setArtifactId(artifactId);
@ -114,7 +115,7 @@ class IncludeFilterTests {
return include; 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); Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId); given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId); 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;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.api.io.TempDir;
@ -38,6 +39,7 @@ import static org.mockito.Mockito.mock;
class JarTypeFilterTests { class JarTypeFilterTests {
@TempDir @TempDir
@SuppressWarnings("NullAway.Init")
Path temp; Path temp;
@Test @Test
@ -70,7 +72,7 @@ class JarTypeFilterTests {
assertThat(new JarTypeFilter().filter(createArtifactWithNoManifest())).isFalse(); assertThat(new JarTypeFilter().filter(createArtifactWithNoManifest())).isFalse();
} }
private Artifact createArtifact(String springBootJarType) { private Artifact createArtifact(@Nullable String springBootJarType) {
Path jarPath = this.temp.resolve("test.jar"); Path jarPath = this.temp.resolve("test.jar");
Manifest manifest = new Manifest(); Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0"); 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;
import java.nio.file.attribute.FileTime; import java.nio.file.attribute.FileTime;
import java.time.Instant; import java.time.Instant;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -88,11 +89,11 @@ class MavenBuildOutputTimestampTests {
assertThat(parseFileTime("2019-10-05T14:37:42Z")).isEqualTo(FileTime.fromMillis(1570286262000L)); 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(); return new MavenBuildOutputTimestamp(timestamp).toInstant();
} }
private static FileTime parseFileTime(String timestamp) { private static @Nullable FileTime parseFileTime(@Nullable String timestamp) {
return new MavenBuildOutputTimestamp(timestamp).toFileTime(); 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;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
@ -40,14 +41,17 @@ class PropertiesMergingResourceTransformerTests {
@Test @Test
void testProcess() throws Exception { void testProcess() throws Exception {
assertThat(this.transformer.hasTransformedResource()).isFalse(); 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(); assertThat(this.transformer.hasTransformedResource()).isTrue();
} }
@Test @Test
void testMerge() throws Exception { void testMerge() throws Exception {
this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), null, 0); this.transformer.processResource("foo", new ByteArrayInputStream("foo=bar".getBytes()), Collections.emptyList(),
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()), null, 0); 0);
this.transformer.processResource("bar", new ByteArrayInputStream("foo=spam".getBytes()),
Collections.emptyList(), 0);
assertThat(this.transformer.getData().getProperty("foo")).isEqualTo("bar,spam"); assertThat(this.transformer.getData().getProperty("foo")).isEqualTo("bar,spam");
} }
@ -55,7 +59,8 @@ class PropertiesMergingResourceTransformerTests {
void testOutput() throws Exception { void testOutput() throws Exception {
this.transformer.setResource("foo"); this.transformer.setResource("foo");
long time = 1592911068000L; 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(); ByteArrayOutputStream out = new ByteArrayOutputStream();
JarOutputStream os = new JarOutputStream(out); JarOutputStream os = new JarOutputStream(out);
this.transformer.modifyOutputStream(os); this.transformer.modifyOutputStream(os);

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

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

Loading…
Cancel
Save