From a57e6495dd6a2c904f5b2b154ba7ff55e07a4e7e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 18 Jul 2017 20:22:24 -0700 Subject: [PATCH] Migrate from FileSystemUtils.deleteRecursively Update test to migrate away from the now deprecated FileSystemUtils. --- .../consumer/SampleIntegrationApplicationTests.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java index b9ff96f52d..08048577a6 100644 --- a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java @@ -19,6 +19,10 @@ package sample.integration.consumer; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.nio.file.FileVisitOption; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Comparator; import java.util.concurrent.Callable; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -35,7 +39,6 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternUtils; -import org.springframework.util.FileSystemUtils; import org.springframework.util.StreamUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -51,14 +54,16 @@ public class SampleIntegrationApplicationTests { private ConfigurableApplicationContext context; @Before - public void deleteInputAndOutput() throws InterruptedException { + public void deleteInputAndOutput() throws InterruptedException, IOException { deleteIfExists(new File("target/input")); deleteIfExists(new File("target/output")); } - private void deleteIfExists(File directory) throws InterruptedException { + private void deleteIfExists(File directory) throws InterruptedException, IOException { if (directory.exists()) { - assertThat(FileSystemUtils.deleteRecursively(directory)).isTrue(); + Files.walk(directory.toPath(), FileVisitOption.FOLLOW_LINKS) + .sorted(Comparator.reverseOrder()).map(Path::toFile) + .forEach(File::delete); } }