|
@@ -23,9 +23,14 @@ package com.dmdirc.actions;
|
23
|
23
|
|
24
|
24
|
import com.dmdirc.actions.interfaces.ActionType;
|
25
|
25
|
|
|
26
|
+import com.dmdirc.util.ConfigFile;
|
|
27
|
+import com.dmdirc.util.InvalidConfigFileException;
|
|
28
|
+import com.dmdirc.util.TextFile;
|
26
|
29
|
import java.io.File;
|
|
30
|
+import java.io.IOException;
|
27
|
31
|
import java.util.ArrayList;
|
28
|
32
|
|
|
33
|
+import java.util.Arrays;
|
29
|
34
|
import org.junit.Test;
|
30
|
35
|
import static org.junit.Assert.*;
|
31
|
36
|
|
|
@@ -53,17 +58,17 @@ public class ActionTest extends junit.framework.TestCase {
|
53
|
58
|
new File(ActionManager.getDirectory() + "unit-test-two"
|
54
|
59
|
+ File.separator + "test1").isFile());
|
55
|
60
|
}
|
56
|
|
-
|
|
61
|
+
|
57
|
62
|
@Test
|
58
|
63
|
public void testSetName() {
|
59
|
64
|
action.setName("test2");
|
60
|
|
-
|
|
65
|
+
|
61
|
66
|
assertFalse("setName must remove old file",
|
62
|
67
|
new File(ActionManager.getDirectory() + "unit-test-two"
|
63
|
68
|
+ File.separator + "test1").isFile());
|
64
|
69
|
assertTrue("setName must create new file",
|
65
|
70
|
new File(ActionManager.getDirectory() + "unit-test-two"
|
66
|
|
- + File.separator + "test2").isFile());
|
|
71
|
+ + File.separator + "test2").isFile());
|
67
|
72
|
}
|
68
|
73
|
|
69
|
74
|
@Test
|
|
@@ -75,4 +80,23 @@ public class ActionTest extends junit.framework.TestCase {
|
75
|
80
|
+ File.separator + "test2").isFile());
|
76
|
81
|
}
|
77
|
82
|
|
|
83
|
+ @Test
|
|
84
|
+ public void testRead() throws IOException, InvalidConfigFileException {
|
|
85
|
+ ActionManager.init();
|
|
86
|
+
|
|
87
|
+ final Action action = new Action("unit-test", "doesn't_exist");
|
|
88
|
+ action.config = new ConfigFile(new TextFile(getClass().getResourceAsStream("action1")));
|
|
89
|
+ action.config.read();
|
|
90
|
+ action.loadActionFromConfig();
|
|
91
|
+
|
|
92
|
+ assertTrue(Arrays.equals(action.getTriggers(),
|
|
93
|
+ new ActionType[]{CoreActionType.SERVER_AWAY}));
|
|
94
|
+ assertEquals("(0&1)", action.getConditionTree().toString());
|
|
95
|
+ assertTrue(Arrays.equals(action.getResponse(), new String[]{"/away"}));
|
|
96
|
+ assertEquals(new ActionCondition(1, CoreActionComponent.STRING_LENGTH,
|
|
97
|
+ CoreActionComparison.INT_EQUALS, "0"), action.getConditions().get(0));
|
|
98
|
+ assertEquals(new ActionCondition("foo", CoreActionComparison.STRING_CONTAINS,
|
|
99
|
+ "bar"), action.getConditions().get(1));
|
|
100
|
+ }
|
|
101
|
+
|
78
|
102
|
}
|