1
|
|
package abbot.script;
|
2
|
|
|
3
|
|
import java.lang.reflect.Method;
|
4
|
|
import java.awt.*;
|
5
|
|
import java.awt.event.*;
|
6
|
|
import java.util.HashMap;
|
7
|
|
|
8
|
|
import junit.extensions.abbot.*;
|
9
|
|
import abbot.finder.ComponentFinder;
|
10
|
|
import abbot.finder.Hierarchy;
|
11
|
|
import abbot.tester.ComponentLocation;
|
12
|
|
|
13
|
|
public class ActionTest extends ComponentTestFixture {
|
14
|
|
|
15
|
1
|
public void testMethodFixing() throws Throwable {
|
16
|
1
|
Action action = new Action(getResolver(), getName(),
|
17
|
|
"Click", new String[0]);
|
18
|
1
|
assertEquals("Method name should be fixed",
|
19
|
|
"actionClick", action.getMethodName());
|
20
|
|
}
|
21
|
|
|
22
|
|
private class FakeRef extends ComponentReference {
|
23
|
2
|
public FakeRef(Resolver r) {
|
24
|
2
|
super(r, Component.class, new HashMap());
|
25
|
|
}
|
26
|
|
|
27
|
4
|
public Component getComponent(Hierarchy h) { return null; }
|
28
|
|
}
|
29
|
|
|
30
|
|
private class MyAction extends Action {
|
31
|
5
|
public MyAction(Resolver r, String method, String[] args) {
|
32
|
5
|
super(r, getName(), method, args);
|
33
|
|
}
|
34
|
4
|
public Object[] getParameters() throws Exception {
|
35
|
4
|
return evaluateParameters(getMethod(), getArguments());
|
36
|
|
}
|
37
|
|
}
|
38
|
|
|
39
|
1
|
public void testVKPlusModifier() throws Exception {
|
40
|
1
|
ComponentReference ref = new FakeRef(getResolver());
|
41
|
1
|
MyAction action = new MyAction(getResolver(), "actionKeyStroke",
|
42
|
|
new String[] {
|
43
|
|
ref.getID(), "VK_A", "SHIFT_MASK",
|
44
|
|
});
|
45
|
1
|
Object[] params = action.getParameters();
|
46
|
1
|
assertEquals("Second parameter should be an integer",
|
47
|
|
new Integer(KeyEvent.VK_A), params[1]);
|
48
|
1
|
assertEquals("Third parameter should be an integer",
|
49
|
|
new Integer(KeyEvent.SHIFT_MASK), params[2]);
|
50
|
|
}
|
51
|
|
|
52
|
1
|
public void testComponentPlusVK() throws Exception {
|
53
|
1
|
ComponentReference ref = new ComponentReference(getResolver(),
|
54
|
|
Component.class,
|
55
|
|
new HashMap());
|
56
|
1
|
MyAction action = new MyAction(getResolver(), "actionKeyStroke",
|
57
|
|
new String[] {
|
58
|
|
ref.getID(), "VK_X",
|
59
|
|
});
|
60
|
1
|
Method method = action.getMethod();
|
61
|
1
|
Class[] params = method.getParameterTypes();
|
62
|
1
|
assertEquals("First parameter should be a Component",
|
63
|
|
Component.class, params[0]);
|
64
|
1
|
assertEquals("Second parameter should be an integer",
|
65
|
|
int.class, params[1]);
|
66
|
|
}
|
67
|
|
|
68
|
1
|
public void testMultipleModifiers() throws Exception {
|
69
|
1
|
MyAction action = new MyAction(getResolver(), "actionKeyStroke",
|
70
|
|
new String[] {
|
71
|
|
"VK_B",
|
72
|
|
"SHIFT_MASK|ALT_MASK",
|
73
|
|
});
|
74
|
1
|
Object[] params = action.getParameters();
|
75
|
1
|
assertEquals("First parameter should be an integer",
|
76
|
|
new Integer(KeyEvent.VK_B), params[0]);
|
77
|
1
|
assertEquals("Second parameter should be an integer",
|
78
|
|
new Integer(KeyEvent.SHIFT_MASK|KeyEvent.ALT_MASK),
|
79
|
|
params[1]);
|
80
|
|
}
|
81
|
|
|
82
|
1
|
public void testVKArgument() throws Exception {
|
83
|
1
|
MyAction action = new MyAction(getResolver(), "actionKeyStroke",
|
84
|
|
new String[] { "VK_C", });
|
85
|
1
|
Object[] params = action.getParameters();
|
86
|
1
|
assertEquals("First parameter should be an integer",
|
87
|
|
new Integer(KeyEvent.VK_C), params[0]);
|
88
|
|
}
|
89
|
|
|
90
|
1
|
public void testComponentLocationMethod() throws Throwable {
|
91
|
1
|
ComponentReference ref = new FakeRef(getResolver());
|
92
|
1
|
MyAction action = new MyAction(getResolver(), "Click", new String[] {
|
93
|
|
ref.getID(), "(0,0)"
|
94
|
|
});
|
95
|
1
|
String[] args = action.getArguments();
|
96
|
1
|
assertEquals("Wrong component reference ID",
|
97
|
|
ref.getID(), args[0]);
|
98
|
1
|
Object[] params = action.getParameters();
|
99
|
1
|
assertEquals("Second parameter should be a ComponentLocation",
|
100
|
|
new ComponentLocation(new Point(0, 0)), params[1]);
|
101
|
|
}
|
102
|
|
|
103
|
6
|
public ActionTest(String name) { super(name); }
|
104
|
|
|
105
|
0
|
public static void main(String[] args) {
|
106
|
0
|
TestHelper.runTests(args, ActionTest.class);
|
107
|
|
}
|
108
|
|
}
|
109
|
|
|
110
|
|
|