Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/arduino/Arduino.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2020-05-06 21:28:53 +0300
committerCristian Maglie <c.maglie@bug.st>2020-05-11 18:13:17 +0300
commit0e4c900252b35ef439062ce16feb989f0fb732de (patch)
tree1265eff539b8f3e9848c3fa9254614ea978be6d9 /app
parent5700d2b5396750ed1fbd14895951154edd9a6f63 (diff)
AbstractWithPreferencesTest: Clean up files after every test
Previously, this used the DeleteFilesOnShutdown class and a shutdown hook, which would delete the files only after shutdown. However, the shutdown handler would be re-added for every testcase, potentially leading to a lot of threads trying to delete the same files. This uses an alternative: Just keep a list of files to delete inside the testcase and use an @After handler to delete the files directly after each usecase.
Diffstat (limited to 'app')
-rw-r--r--app/test/processing/app/AbstractWithPreferencesTest.java22
1 files changed, 19 insertions, 3 deletions
diff --git a/app/test/processing/app/AbstractWithPreferencesTest.java b/app/test/processing/app/AbstractWithPreferencesTest.java
index f0d2f3a2b..10a690393 100644
--- a/app/test/processing/app/AbstractWithPreferencesTest.java
+++ b/app/test/processing/app/AbstractWithPreferencesTest.java
@@ -29,17 +29,27 @@
package processing.app;
-import cc.arduino.files.DeleteFilesOnShutdown;
import org.junit.Before;
+import org.junit.After;
+
import processing.app.helpers.FileUtils;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
import java.util.Random;
+import java.util.List;
+import java.util.LinkedList;
public abstract class AbstractWithPreferencesTest {
+ /**
+ * Files or directories that will be deleted after each test.
+ * Subclasses can add files here in @Test or @Before functions.
+ */
+ protected List<File> deleteAfter = new LinkedList<File>();
@Before
public void init() throws Exception {
- Runtime.getRuntime().addShutdownHook(new Thread(DeleteFilesOnShutdown.INSTANCE));
BaseNoGui.initPlatform();
BaseNoGui.getPlatform().init();
PreferencesData.init(null);
@@ -48,7 +58,13 @@ public abstract class AbstractWithPreferencesTest {
BaseNoGui.initPackages();
Base.untitledFolder = FileUtils.createTempFolder("untitled" + new Random().nextInt(Integer.MAX_VALUE), ".tmp");
- DeleteFilesOnShutdown.add(Base.untitledFolder);
+ deleteAfter.add(Base.untitledFolder);
}
+ @After
+ public void cleanup() throws IOException {
+ for (File f : deleteAfter)
+ FileUtils.recursiveDelete(f);
+ deleteAfter = new LinkedList<File>();
+ }
}