瀏覽代碼

Action unit test

git-svn-id: http://svn.dmdirc.com/trunk@3828 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 年之前
父節點
當前提交
85f7ec82e3
共有 3 個文件被更改,包括 59 次插入5 次删除
  1. 2
    2
      src/com/dmdirc/actions/Action.java
  2. 27
    3
      test/com/dmdirc/actions/ActionTest.java
  3. 30
    0
      test/com/dmdirc/actions/action1

+ 2
- 2
src/com/dmdirc/actions/Action.java 查看文件

@@ -70,7 +70,7 @@ public class Action extends ActionModel implements Serializable {
70 70
     private String location;
71 71
 
72 72
     /** The config file we're using. */
73
-    private ConfigFile config;
73
+    protected ConfigFile config;
74 74
 
75 75
     /**
76 76
      * Creates a new instance of Action. The group and name specified must
@@ -149,7 +149,7 @@ public class Action extends ActionModel implements Serializable {
149 149
     /**
150 150
      * Loads this action from the config instance.
151 151
      */
152
-    private void loadActionFromConfig() {
152
+    protected void loadActionFromConfig() {
153 153
         if (config.isFlatDomain(DOMAIN_TRIGGERS)) {
154 154
             if (!loadTriggers(config.getFlatDomain(DOMAIN_TRIGGERS))) {
155 155
                 return;

+ 27
- 3
test/com/dmdirc/actions/ActionTest.java 查看文件

@@ -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
 }

+ 30
- 0
test/com/dmdirc/actions/action1 查看文件

@@ -0,0 +1,30 @@
1
+# This is a DMDirc configuration file.
2
+# Written on: Mon Jan 14 06:19:51 GMT 2008
3
+
4
+# This section indicates which sections below take key/value
5
+# pairs, rather than a simple list. It should be placed above
6
+# any sections that take key/values.
7
+keysections:
8
+  condition 0
9
+  condition 1
10
+
11
+triggers:
12
+  SERVER_AWAY
13
+
14
+response:
15
+  /away
16
+
17
+conditiontree:
18
+  (0&1)
19
+
20
+condition 0:
21
+  argument=1
22
+  component=STRING_LENGTH
23
+  target=0
24
+  comparison=INT_EQUALS
25
+
26
+condition 1:
27
+  argument=-1
28
+  starget=foo
29
+  target=bar
30
+  comparison=STRING_CONTAINS

Loading…
取消
儲存