1
|
|
package example;
|
2
|
|
|
3
|
|
import java.awt.Dimension;
|
4
|
|
import java.awt.event.*;
|
5
|
|
|
6
|
|
import javax.swing.JPanel;
|
7
|
|
|
8
|
|
import junit.extensions.abbot.*;
|
9
|
|
import abbot.tester.ComponentTester;
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
public class ArrowButtonTest extends ComponentTestFixture {
|
18
|
|
|
19
|
|
private ComponentTester tester;
|
20
|
0
|
protected void setUp() {
|
21
|
0
|
tester = ComponentTester.getTester(ArrowButton.class);
|
22
|
|
}
|
23
|
|
|
24
|
|
private String gotClick;
|
25
|
0
|
public void testClick() {
|
26
|
0
|
ActionListener al = new ActionListener() {
|
27
|
0
|
public void actionPerformed(ActionEvent ev) {
|
28
|
0
|
gotClick = ev.getActionCommand();
|
29
|
|
}
|
30
|
|
};
|
31
|
|
|
32
|
0
|
ArrowButton left = new ArrowButton(ArrowButton.LEFT);
|
33
|
0
|
ArrowButton right = new ArrowButton(ArrowButton.RIGHT);
|
34
|
0
|
ArrowButton up = new ArrowButton(ArrowButton.UP);
|
35
|
0
|
ArrowButton down = new ArrowButton(ArrowButton.DOWN);
|
36
|
|
|
37
|
0
|
left.addActionListener(al);
|
38
|
0
|
right.addActionListener(al);
|
39
|
0
|
up.addActionListener(al);
|
40
|
0
|
down.addActionListener(al);
|
41
|
|
|
42
|
0
|
JPanel pane = new JPanel();
|
43
|
0
|
pane.add(left);
|
44
|
0
|
pane.add(right);
|
45
|
0
|
pane.add(up);
|
46
|
0
|
pane.add(down);
|
47
|
|
|
48
|
0
|
showFrame(pane);
|
49
|
|
|
50
|
0
|
gotClick = null;
|
51
|
0
|
tester.actionClick(left);
|
52
|
0
|
assertEquals("Action failed", ArrowButton.LEFT, gotClick);
|
53
|
0
|
gotClick = null;
|
54
|
0
|
tester.actionClick(right);
|
55
|
0
|
assertEquals("Action failed", ArrowButton.RIGHT, gotClick);
|
56
|
0
|
gotClick = null;
|
57
|
0
|
tester.actionClick(up);
|
58
|
0
|
assertEquals("Action failed", ArrowButton.UP, gotClick);
|
59
|
0
|
gotClick = null;
|
60
|
0
|
tester.actionClick(down);
|
61
|
0
|
assertEquals("Action failed", ArrowButton.DOWN, gotClick);
|
62
|
|
}
|
63
|
|
|
64
|
|
private int count = 0;
|
65
|
0
|
public void testRepeatedFire() {
|
66
|
0
|
ArrowButton arrow = new ArrowButton(ArrowButton.LEFT);
|
67
|
0
|
ActionListener al = new ActionListener() {
|
68
|
0
|
public void actionPerformed(ActionEvent ev) {
|
69
|
0
|
++count;
|
70
|
|
}
|
71
|
|
};
|
72
|
0
|
arrow.addActionListener(al);
|
73
|
0
|
showFrame(arrow);
|
74
|
|
|
75
|
|
|
76
|
0
|
tester.mousePress(arrow);
|
77
|
0
|
tester.actionDelay(5000);
|
78
|
0
|
tester.mouseRelease();
|
79
|
0
|
assertTrue("Didn't get any repeated events", count > 1);
|
80
|
|
}
|
81
|
|
|
82
|
0
|
public ArrowButtonTest(String name) { super(name); }
|
83
|
|
|
84
|
0
|
public static void main(String[] args) {
|
85
|
0
|
TestHelper.runTests(args, ArrowButtonTest.class);
|
86
|
|
}
|
87
|
|
}
|
88
|
|
|