Skip to content

Commit 33c925d

Browse files
committed
Use @TempDir where feasible
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
1 parent 92c3d18 commit 33c925d

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

build-plugin/spring-boot-gradle-plugin/src/dockerTest/java/org/springframework/boot/gradle/tasks/bundling/BootBuildImageIntegrationTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.junit.jupiter.api.TestTemplate;
3939
import org.junit.jupiter.api.condition.EnabledOnOs;
4040
import org.junit.jupiter.api.condition.OS;
41+
import org.junit.jupiter.api.io.TempDir;
4142

4243
import org.springframework.boot.buildpack.platform.docker.DockerApi;
4344
import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi;
@@ -62,6 +63,7 @@
6263
* @author Andy Wilkinson
6364
* @author Scott Frederick
6465
* @author Rafael Ceccone
66+
* @author Yanming Zhou
6567
*/
6668
@GradleCompatibility(configurationCache = true)
6769
@DisabledIfDockerUnavailable
@@ -318,7 +320,7 @@ void buildsImageWithVolumeCaches() throws IOException {
318320
@TestTemplate
319321
@EnabledOnOs(value = OS.LINUX, disabledReason = "Works with Docker Engine on Linux but is not reliable with "
320322
+ "Docker Desktop on other OSs")
321-
void buildsImageWithBindCaches() throws IOException {
323+
void buildsImageWithBindCaches(@TempDir Path tempDir) throws IOException {
322324
writeMainClass();
323325
writeLongNameResource();
324326
BuildResult result = this.gradleBuild.build("bootBuildImage");
@@ -328,9 +330,8 @@ void buildsImageWithBindCaches() throws IOException {
328330
assertThat(result.getOutput()).contains("---> Test Info buildpack building");
329331
assertThat(result.getOutput()).contains("---> Test Info buildpack done");
330332
removeImages(projectName);
331-
String tempDir = System.getProperty("java.io.tmpdir");
332-
Path buildCachePath = Paths.get(tempDir, "junit-image-cache-" + projectName + "-build");
333-
Path launchCachePath = Paths.get(tempDir, "junit-image-cache-" + projectName + "-launch");
333+
Path buildCachePath = tempDir.resolve("junit-image-cache-" + projectName + "-build");
334+
Path launchCachePath = tempDir.resolve("junit-image-cache-" + projectName + "-launch");
334335
assertThat(buildCachePath).exists().isDirectory();
335336
assertThat(launchCachePath).exists().isDirectory();
336337
cleanupCache(buildCachePath);

build-plugin/spring-boot-maven-plugin/src/dockerTest/java/org/springframework/boot/maven/BuildImageTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.jupiter.api.condition.EnabledOnOs;
3030
import org.junit.jupiter.api.condition.OS;
3131
import org.junit.jupiter.api.extension.ExtendWith;
32+
import org.junit.jupiter.api.io.TempDir;
3233

3334
import org.springframework.boot.buildpack.platform.docker.DockerApi;
3435
import org.springframework.boot.buildpack.platform.docker.DockerApi.ImageApi;
@@ -49,6 +50,7 @@
4950
* @author Stephane Nicoll
5051
* @author Scott Frederick
5152
* @author Rafael Ceccone
53+
* @author Yanming Zhou
5254
*/
5355
@ExtendWith(MavenBuildExtension.class)
5456
@DisabledIfDockerUnavailable
@@ -443,7 +445,7 @@ void whenBuildImageIsInvokedWithVolumeCaches(MavenBuild mavenBuild) {
443445
@TestTemplate
444446
@EnabledOnOs(value = OS.LINUX, disabledReason = "Works with Docker Engine on Linux but is not reliable with "
445447
+ "Docker Desktop on other OSs")
446-
void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild) {
448+
void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild, @TempDir Path tempDir) {
447449
String testBuildId = randomString();
448450
mavenBuild.project("dockerTest", "build-image-bind-caches")
449451
.goals("package")
@@ -454,9 +456,8 @@ void whenBuildImageIsInvokedWithBindCaches(MavenBuild mavenBuild) {
454456
.contains("docker.io/library/build-image-bind-caches:0.0.1.BUILD-SNAPSHOT")
455457
.contains("Successfully built image");
456458
removeImage("build-image-bind-caches", "0.0.1.BUILD-SNAPSHOT");
457-
String tempDir = System.getProperty("java.io.tmpdir");
458-
Path buildCachePath = Paths.get(tempDir, "junit-image-cache-" + testBuildId + "-build");
459-
Path launchCachePath = Paths.get(tempDir, "junit-image-cache-" + testBuildId + "-launch");
459+
Path buildCachePath = tempDir.resolve("junit-image-cache-" + testBuildId + "-build");
460+
Path launchCachePath = tempDir.resolve("junit-image-cache-" + testBuildId + "-launch");
460461
assertThat(buildCachePath).exists().isDirectory();
461462
assertThat(launchCachePath).exists().isDirectory();
462463
cleanupCache(buildCachePath);

0 commit comments

Comments
 (0)