01: package abbot.editor.recorder;
02:
03: import java.awt.*;
04: import java.awt.event.InputEvent;
05: import javax.swing.*;
06:
07: import junit.extensions.abbot.RepeatHelper;
08: import abbot.script.Resolver;
09: import abbot.tester.*;
10:
11: /**
12: * Unit test to verify proper capture of user semantic events on a JTree.
13: */
14: public class JTreeRecorderTest extends AbstractSemanticRecorderFixture {
15:
16: private JTreeTester tester;
17: private JTree tree;
18:
19: protected SemanticRecorder createSemanticRecorder(Resolver r) {
20: return new JTreeRecorder(r);
21: }
22:
23: public void testCaptureRowSelection() {
24: startRecording();
25: tester.actionSelectRow(tree, 1);
26: assertStep("SelectRow\\(.*\"\\[JTree, colors\\]\"\\)");
27: }
28:
29: public void testCaptureRowSelectionHiddenRoot() {
30: tree.setRootVisible(false);
31: startRecording();
32: tester.actionSelectRow(tree, 1);
33: assertStep("SelectRow\\(.*\"\\[sports\\]\"\\)");
34: }
35:
36: public void testCaptureMultipleClick() {
37: startRecording();
38: int row = 2;
39: tester.actionClick(tree, new JTreeLocation(row),
40: InputEvent.BUTTON1_MASK, 2);
41: assertStep("Click\\(.*,\"\\[JTree, sports\\]\",BUTTON1_MASK,2\\)");
42: }
43:
44: public void testCaptureToggleRow() {
45: startRecording();
46: int row = 2;
47: Rectangle bounds = new JTreeLocation(row).getBounds(tree);
48: // Make a reasonable guess of the proper location.
49: Point pt = new Point(bounds.x - bounds.height / 2, bounds.y
50: + bounds.height / 2);
51: tester.actionClick(tree, pt.x, pt.y);
52: assertStep("ToggleRow\\(.*,\"\\[JTree, sports\\]\"\\)");
53: }
54:
55: public void testCapturePopup() {
56: final String NAME = "item 1";
57: JPopupMenu menu = new JPopupMenu();
58: menu.add(new JMenuItem(NAME));
59: addPopup(tree, menu);
60: startRecording();
61: tester.actionSelectPopupMenuItem(tree, 0, 0, NAME);
62: assertStep("SelectPopupMenuItem\\(.*,\"\\[JTree\\]\"," + NAME
63: + "\\)");
64: }
65:
66: protected void setUp() {
67: tree = new JTree();
68: tester = (JTreeTester) ComponentTester.getTester(tree);
69: showFrame(tree);
70: }
71:
72: public JTreeRecorderTest(String name) {
73: super (name);
74: }
75:
76: public static void main(String[] args) {
77: RepeatHelper.runTests(args, JTreeRecorderTest.class);
78: }
79: }
|