From 22c441f1dcdc535d002bed6e5eabc59598dced29 Mon Sep 17 00:00:00 2001 From: James Nord Date: Thu, 23 Feb 2023 14:38:13 +0000 Subject: [PATCH] close stream so directory can be cleaned --- .../jenkins/plugins/advisor/BundleUploadTest.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/cloudbees/jenkins/plugins/advisor/BundleUploadTest.java b/src/test/java/com/cloudbees/jenkins/plugins/advisor/BundleUploadTest.java index 78ad578..c7baf85 100644 --- a/src/test/java/com/cloudbees/jenkins/plugins/advisor/BundleUploadTest.java +++ b/src/test/java/com/cloudbees/jenkins/plugins/advisor/BundleUploadTest.java @@ -12,9 +12,11 @@ import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.TimeUnit; - +import java.util.stream.Collectors; +import java.util.stream.Stream; import static com.cloudbees.jenkins.plugins.advisor.BundleUpload.BUNDLE_SUCCESSFULLY_UPLOADED; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.any; @@ -30,6 +32,7 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; import static java.lang.String.format; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertFalse; @@ -80,7 +83,9 @@ public void execute() throws Exception { // Refresh the configuration? assertThat(config.getLastBundleResult(), containsString(BUNDLE_SUCCESSFULLY_UPLOADED)); - assertThat(Files.list(Paths.get(BundleUpload.TEMP_BUNDLE_DIRECTORY)).count(), is(equalTo(0L))); + try (Stream children = Files.list(Paths.get(BundleUpload.TEMP_BUNDLE_DIRECTORY))) { + assertThat(children.collect(Collectors.toList()), is(empty())); + } } @Test