|
54 | 54 | import org.junit.jupiter.api.TestInstance; |
55 | 55 | import org.junit.jupiter.api.condition.DisabledOnOs; |
56 | 56 | import org.junit.jupiter.api.condition.OS; |
| 57 | +import org.junit.jupiter.api.extension.AnnotatedElementContext; |
| 58 | +import org.junit.jupiter.api.extension.ExtensionContext; |
57 | 59 | import org.junit.jupiter.api.extension.RegisterExtension; |
58 | 60 | import org.junit.jupiter.api.io.TempDir; |
| 61 | +import org.junit.jupiter.api.io.TempDirFactory; |
59 | 62 | import org.sonarqube.ws.client.WsClient; |
60 | 63 | import org.sonarqube.ws.client.permissions.RemoveGroupRequest; |
61 | 64 | import org.sonarqube.ws.client.settings.SetRequest; |
@@ -135,7 +138,7 @@ class SonarQubeEnterpriseEditionTests extends AbstractConnectedTests { |
135 | 138 |
|
136 | 139 | private static WsClient adminWsClient; |
137 | 140 |
|
138 | | - @TempDir |
| 141 | + @TempDir(factory = CustomTempDirFactory.class) |
139 | 142 | private static Path sonarUserHome; |
140 | 143 |
|
141 | 144 | private static SonarLintRpcServer backend; |
@@ -200,6 +203,27 @@ void stop() { |
200 | 203 | ((MockSonarLintRpcClientDelegate) client).clear(); |
201 | 204 | } |
202 | 205 |
|
| 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 | + |
203 | 227 | @Nested |
204 | 228 | // TODO Can be removed when switching to Java 16+ and changing prepare() to static |
205 | 229 | @TestInstance(TestInstance.Lifecycle.PER_CLASS) |
|
0 commit comments