Use @TempDir in FileSystemUtilsTests
This commit is contained in:
parent
6c27dbc095
commit
7a6f9bd3c3
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 java.io.File;
|
||||||
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Tests for {@link FileSystemUtils}.
|
||||||
|
*
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
|
* @author Sam Brannen
|
||||||
*/
|
*/
|
||||||
class FileSystemUtilsTests {
|
class FileSystemUtilsTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void deleteRecursively() throws Exception {
|
void deleteRecursively(@TempDir File tempDir) throws Exception {
|
||||||
File root = new File("./tmp/root");
|
File root = new File(tempDir, "root");
|
||||||
File child = new File(root, "child");
|
File child = new File(root, "child");
|
||||||
File grandchild = new File(child, "grandchild");
|
File grandchild = new File(child, "grandchild");
|
||||||
|
|
||||||
|
@ -53,8 +56,8 @@ class FileSystemUtilsTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void copyRecursively() throws Exception {
|
void copyRecursively(@TempDir File tempDir) throws Exception {
|
||||||
File src = new File("./tmp/src");
|
File src = new File(tempDir, "src");
|
||||||
File child = new File(src, "child");
|
File child = new File(src, "child");
|
||||||
File grandchild = new File(child, "grandchild");
|
File grandchild = new File(child, "grandchild");
|
||||||
|
|
||||||
|
@ -68,7 +71,7 @@ class FileSystemUtilsTests {
|
||||||
assertThat(grandchild).exists();
|
assertThat(grandchild).exists();
|
||||||
assertThat(bar).exists();
|
assertThat(bar).exists();
|
||||||
|
|
||||||
File dest = new File("./dest");
|
File dest = new File(tempDir, "/dest");
|
||||||
FileSystemUtils.copyRecursively(src, dest);
|
FileSystemUtils.copyRecursively(src, dest);
|
||||||
|
|
||||||
assertThat(dest).exists();
|
assertThat(dest).exists();
|
||||||
|
@ -78,17 +81,4 @@ class FileSystemUtilsTests {
|
||||||
assertThat(src).doesNotExist();
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue