Add nullability annotations to tests in loader/spring-boot-jarmode-tools
See gh-47263
This commit is contained in:
parent
8108678bc5
commit
6f94129c85
|
|
@ -30,3 +30,7 @@ dependencies {
|
|||
testImplementation("org.mockito:mockito-core")
|
||||
testImplementation("org.mockito:mockito-junit-jupiter")
|
||||
}
|
||||
|
||||
tasks.named("compileTestJava") {
|
||||
options.nullability.checking = "tests"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import java.util.jar.Manifest;
|
|||
import java.util.stream.Stream;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
|
@ -51,6 +52,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
abstract class AbstractJarModeTests {
|
||||
|
||||
@TempDir
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
File tempDir;
|
||||
|
||||
Manifest createManifest(String... entries) {
|
||||
|
|
@ -74,8 +76,8 @@ abstract class AbstractJarModeTests {
|
|||
return createArchive(manifest, null, null, null, entries);
|
||||
}
|
||||
|
||||
File createArchive(Manifest manifest, Instant creationTime, Instant lastModifiedTime, Instant lastAccessTime,
|
||||
String... entries) throws IOException {
|
||||
File createArchive(Manifest manifest, @Nullable Instant creationTime, @Nullable Instant lastModifiedTime,
|
||||
@Nullable Instant lastAccessTime, String... entries) throws IOException {
|
||||
Assert.state(entries.length % 2 == 0, "Entries must be key value pairs");
|
||||
File file = new File(this.tempDir, "test.jar");
|
||||
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(file), manifest)) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.jarmode.tools.Command.Option;
|
||||
|
|
@ -165,9 +166,9 @@ class CommandTests {
|
|||
|
||||
static class TestCommand extends Command {
|
||||
|
||||
private Map<Option, String> runOptions;
|
||||
private @Nullable Map<Option, @Nullable String> runOptions;
|
||||
|
||||
private List<String> runParameters;
|
||||
private @Nullable List<String> runParameters;
|
||||
|
||||
TestCommand(String name, Option... options) {
|
||||
this(name, "test", Options.of(options), Parameters.none());
|
||||
|
|
@ -178,16 +179,16 @@ class CommandTests {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
|
||||
protected void run(PrintStream out, Map<Option, @Nullable String> options, List<String> parameters) {
|
||||
this.runOptions = options;
|
||||
this.runParameters = parameters;
|
||||
}
|
||||
|
||||
Map<Option, String> getRunOptions() {
|
||||
@Nullable Map<Option, @Nullable String> getRunOptions() {
|
||||
return this.runOptions;
|
||||
}
|
||||
|
||||
List<String> getRunParameters() {
|
||||
@Nullable List<String> getRunParameters() {
|
||||
return this.runParameters;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,9 +34,11 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
|||
class ContextTests {
|
||||
|
||||
@TempDir
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
File temp;
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("NullAway") // Test null check
|
||||
void createWhenSourceIsNullThrowsException() {
|
||||
assertThatIllegalStateException().isThrownBy(() -> new Context(null, this.temp))
|
||||
.withMessage("Unable to find source archive");
|
||||
|
|
|
|||
|
|
@ -297,7 +297,7 @@ class ExtractCommandTests extends AbstractJarModeTests {
|
|||
|
||||
@Test
|
||||
void runWithJarFileThatWouldWriteEntriesOutsideDestinationFails() throws Exception {
|
||||
File file = createArchive("e/../../e.jar", null);
|
||||
File file = createArchive("e/../../e.jar", "");
|
||||
assertThatIllegalStateException().isThrownBy(() -> run(file, "--launcher"))
|
||||
.withMessageContaining("Entry 'e/../../e.jar' would be written");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,9 +69,11 @@ class ExtractLayersCommandTests {
|
|||
private static final FileTime LAST_ACCESS_TIME = FileTime.from(NOW.minus(1, ChronoUnit.DAYS));
|
||||
|
||||
@TempDir
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
File temp;
|
||||
|
||||
@Mock
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Context context;
|
||||
|
||||
private File jarFile;
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ class HelpCommandTests {
|
|||
private TestPrintStream out;
|
||||
|
||||
@TempDir
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
Path temp;
|
||||
|
||||
@BeforeEach
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class IndexedJarStructureTests {
|
|||
void shouldResolveLibraryEntry() throws IOException {
|
||||
IndexedJarStructure structure = createStructure();
|
||||
Entry entry = structure.resolve("BOOT-INF/lib/spring-webmvc-6.1.4.jar");
|
||||
assertThat(entry).isNotNull();
|
||||
assertThat(entry.location()).isEqualTo("spring-webmvc-6.1.4.jar");
|
||||
assertThat(entry.originalLocation()).isEqualTo("BOOT-INF/lib/spring-webmvc-6.1.4.jar");
|
||||
assertThat(entry.type()).isEqualTo(Type.LIBRARY);
|
||||
|
|
@ -56,6 +57,7 @@ class IndexedJarStructureTests {
|
|||
void shouldResolveApplicationEntry() throws IOException {
|
||||
IndexedJarStructure structure = createStructure();
|
||||
Entry entry = structure.resolve("BOOT-INF/classes/application.properties");
|
||||
assertThat(entry).isNotNull();
|
||||
assertThat(entry.location()).isEqualTo("application.properties");
|
||||
assertThat(entry.originalLocation()).isEqualTo("BOOT-INF/classes/application.properties");
|
||||
assertThat(entry.type()).isEqualTo(Type.APPLICATION_CLASS_OR_RESOURCE);
|
||||
|
|
@ -65,6 +67,7 @@ class IndexedJarStructureTests {
|
|||
void shouldResolveLoaderEntry() throws IOException {
|
||||
IndexedJarStructure structure = createStructure();
|
||||
Entry entry = structure.resolve("org/springframework/boot/loader/launch/JarLauncher");
|
||||
assertThat(entry).isNotNull();
|
||||
assertThat(entry.location()).isEqualTo("org/springframework/boot/loader/launch/JarLauncher");
|
||||
assertThat(entry.originalLocation()).isEqualTo("org/springframework/boot/loader/launch/JarLauncher");
|
||||
assertThat(entry.type()).isEqualTo(Type.LOADER);
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ import static org.mockito.Mockito.mock;
|
|||
class IndexedLayersTests {
|
||||
|
||||
@TempDir
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
File temp;
|
||||
|
||||
@Test
|
||||
|
|
@ -94,6 +95,7 @@ class IndexedLayersTests {
|
|||
Context context = mock(Context.class);
|
||||
given(context.getArchiveFile()).willReturn(createWarFile("test.war"));
|
||||
IndexedLayers layers = IndexedLayers.get(context);
|
||||
assertThat(layers).isNotNull();
|
||||
assertThat(layers.getLayer(mockEntry("WEB-INF/lib/a.jar"))).isEqualTo("test");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ class LayerToolsJarModeTests {
|
|||
private PrintStream systemOut;
|
||||
|
||||
@TempDir
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
File temp;
|
||||
|
||||
@BeforeEach
|
||||
|
|
|
|||
|
|
@ -48,9 +48,11 @@ import static org.mockito.BDDMockito.given;
|
|||
class ListCommandTests {
|
||||
|
||||
@TempDir
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
File temp;
|
||||
|
||||
@Mock
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
private Context context;
|
||||
|
||||
private ListCommand command;
|
||||
|
|
@ -68,6 +70,7 @@ class ListCommandTests {
|
|||
@Test
|
||||
void listLayersShouldListLayers() {
|
||||
Layers layers = IndexedLayers.get(this.context);
|
||||
assertThat(layers).isNotNull();
|
||||
this.command.printLayers(layers, this.out);
|
||||
assertThat(this.out).hasSameContentAsResource("list-output-without-deprecation.txt");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import java.io.PrintStream;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Moritz Halbritter
|
||||
*/
|
||||
|
|
@ -33,7 +35,7 @@ class TestCommand extends Command {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void run(PrintStream out, Map<Option, String> options, List<String> parameters) {
|
||||
protected void run(PrintStream out, Map<Option, @Nullable String> options, List<String> parameters) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue