Use @⁠TempDir in FileSystemUtilsTests

This commit is contained in:
Sam Brannen 2025-06-06 16:34:56 +02:00
parent 6c27dbc095
commit 7a6f9bd3c3
1 changed files with 10 additions and 20 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,19 +18,22 @@ package org.springframework.util;
import java.io.File;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link FileSystemUtils}.
*
* @author Rob Harrop
* @author Sam Brannen
*/
class FileSystemUtilsTests {
@Test
void deleteRecursively() throws Exception {
File root = new File("./tmp/root");
void deleteRecursively(@TempDir File tempDir) throws Exception {
File root = new File(tempDir, "root");
File child = new File(root, "child");
File grandchild = new File(child, "grandchild");
@ -53,8 +56,8 @@ class FileSystemUtilsTests {
}
@Test
void copyRecursively() throws Exception {
File src = new File("./tmp/src");
void copyRecursively(@TempDir File tempDir) throws Exception {
File src = new File(tempDir, "src");
File child = new File(src, "child");
File grandchild = new File(child, "grandchild");
@ -68,7 +71,7 @@ class FileSystemUtilsTests {
assertThat(grandchild).exists();
assertThat(bar).exists();
File dest = new File("./dest");
File dest = new File(tempDir, "/dest");
FileSystemUtils.copyRecursively(src, dest);
assertThat(dest).exists();
@ -78,17 +81,4 @@ class FileSystemUtilsTests {
assertThat(src).doesNotExist();
}
@AfterEach
void tearDown() {
File tmp = new File("./tmp");
if (tmp.exists()) {
FileSystemUtils.deleteRecursively(tmp);
}
File dest = new File("./dest");
if (dest.exists()) {
FileSystemUtils.deleteRecursively(dest);
}
}
}