Skip to content

Commit 05ccea4

Browse files
Try debug JUnit closure issue
1 parent 9b9ee4d commit 05ccea4

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

its/tests/src/test/java/its/SonarQubeEnterpriseEditionTests.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@
5454
import org.junit.jupiter.api.TestInstance;
5555
import org.junit.jupiter.api.condition.DisabledOnOs;
5656
import org.junit.jupiter.api.condition.OS;
57+
import org.junit.jupiter.api.extension.AnnotatedElementContext;
58+
import org.junit.jupiter.api.extension.ExtensionContext;
5759
import org.junit.jupiter.api.extension.RegisterExtension;
5860
import org.junit.jupiter.api.io.TempDir;
61+
import org.junit.jupiter.api.io.TempDirFactory;
5962
import org.sonarqube.ws.client.WsClient;
6063
import org.sonarqube.ws.client.permissions.RemoveGroupRequest;
6164
import org.sonarqube.ws.client.settings.SetRequest;
@@ -135,7 +138,7 @@ class SonarQubeEnterpriseEditionTests extends AbstractConnectedTests {
135138

136139
private static WsClient adminWsClient;
137140

138-
@TempDir
141+
@TempDir(factory = CustomTempDirFactory.class)
139142
private static Path sonarUserHome;
140143

141144
private static SonarLintRpcServer backend;
@@ -200,6 +203,27 @@ void stop() {
200203
((MockSonarLintRpcClientDelegate) client).clear();
201204
}
202205

206+
private static class CustomTempDirFactory extends TempDirFactory.Standard {
207+
208+
private Path tempDirectory;
209+
210+
@Override
211+
public Path createTempDirectory(AnnotatedElementContext elementContext, ExtensionContext extensionContext) throws IOException {
212+
tempDirectory = super.createTempDirectory(elementContext, extensionContext);
213+
return tempDirectory;
214+
}
215+
216+
@Override
217+
public void close() throws IOException {
218+
if (Files.exists(tempDirectory)) {
219+
System.out.println("TempDir was not deleted " + tempDirectory);
220+
try (var files = Files.walk(tempDirectory)) {
221+
files.forEach(file -> System.out.println("File " + file + "still exists"));
222+
}
223+
}
224+
}
225+
}
226+
203227
@Nested
204228
// TODO Can be removed when switching to Java 16+ and changing prepare() to static
205229
@TestInstance(TestInstance.Lifecycle.PER_CLASS)

0 commit comments

Comments
 (0)