forked from processing/processing4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommanderTest.java
More file actions
89 lines (70 loc) · 2.42 KB
/
CommanderTest.java
File metadata and controls
89 lines (70 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package processing.mode.java;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import processing.app.Settings;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import static org.junit.Assert.*;
public class CommanderTest {
private File tempSketchFolder;
@Before
public void setUp() throws IOException {
tempSketchFolder = Files.createTempDirectory("sketch_test").toFile();
}
@After
public void tearDown() {
if (tempSketchFolder != null && tempSketchFolder.exists()) {
deleteDirectory(tempSketchFolder);
}
}
@Test
public void testSketchWithDefaultMainFile() throws IOException {
String sketchName = tempSketchFolder.getName();
File mainFile = new File(tempSketchFolder, sketchName + ".pde");
try (FileWriter writer = new FileWriter(mainFile)) {
writer.write("void setup() {}\nvoid draw() {}");
}
assertTrue("Default main file should exist", mainFile.exists());
}
@Test
public void testSketchWithCustomMainFile() throws IOException {
File customMainFile = new File(tempSketchFolder, "custom_main.pde");
try (FileWriter writer = new FileWriter(customMainFile)) {
writer.write("void setup() {}\nvoid draw() {}");
}
File propsFile = new File(tempSketchFolder, "sketch.properties");
Settings props = new Settings(propsFile);
props.set("main", "custom_main.pde");
props.save();
assertTrue("Custom main file should exist", customMainFile.exists());
assertTrue("sketch.properties should exist", propsFile.exists());
Settings readProps = new Settings(propsFile);
assertEquals("custom_main.pde", readProps.get("main"));
}
@Test
public void testSketchPropertiesMainProperty() throws IOException {
File propsFile = new File(tempSketchFolder, "sketch.properties");
Settings props = new Settings(propsFile);
props.set("main", "my_sketch.pde");
props.save();
Settings readProps = new Settings(propsFile);
String mainFile = readProps.get("main");
assertEquals("Main property should match", "my_sketch.pde", mainFile);
}
private void deleteDirectory(File directory) {
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isDirectory()) {
deleteDirectory(file);
} else {
file.delete();
}
}
}
directory.delete();
}
}