01: package abbot.editor.recorder;
02:
03: import java.awt.event.InputEvent;
04: import javax.swing.JScrollPane;
05: import javax.swing.JTable;
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 JTable.
13: */
14: public class JTableRecorderTest extends AbstractSemanticRecorderFixture {
15:
16: private JTableTester tester;
17: private JTable table;
18: private static final int MAX_ENTRIES = 4;
19:
20: public JTableRecorderTest(String name) {
21: super (name);
22: }
23:
24: protected SemanticRecorder createSemanticRecorder(Resolver r) {
25: return new JTableRecorder(r);
26: }
27:
28: private void showTable() {
29: String[][] cells = new String[MAX_ENTRIES][MAX_ENTRIES];
30: for (int i = 0; i < MAX_ENTRIES; i++) {
31: for (int j = 0; j < MAX_ENTRIES; j++) {
32: if (i == 0 && j == 0)
33: cells[i][j] = null;
34: else
35: cells[i][j] = "cell " + i + "," + j;
36: }
37: }
38: String[] names = new String[MAX_ENTRIES];
39: for (int i = 0; i < MAX_ENTRIES; i++) {
40: names[i] = "col " + i;
41: }
42: table = new JTable(cells, names);
43: tester = (JTableTester) ComponentTester.getTester(table);
44: showFrame(new JScrollPane(table));
45: }
46:
47: public void testCaptureCellSelection() {
48: showTable();
49: startRecording();
50: for (int i = MAX_ENTRIES - 1; i >= 0; i--) {
51: for (int j = MAX_ENTRIES - 1; j >= 0; j--) {
52: tester.actionSelectCell(table, i, j);
53: if (i == 0 && j == 0)
54: assertStep("SelectCell\\(.*,\\[0,0\\]\\)");
55: else
56: assertStep("SelectCell\\(.*,\"cell " + i + "," + j
57: + "\"\\)");
58: }
59: }
60: }
61:
62: public void testCaptureMultipleClick() {
63: showTable();
64: startRecording();
65: int row = MAX_ENTRIES / 2;
66: int col = MAX_ENTRIES / 2;
67: tester.actionClick(table, new JTableLocation(row, col),
68: InputEvent.BUTTON1_MASK, 2);
69: assertStep("Click\\(.*,\"cell " + row + "," + col
70: + "\",BUTTON1_MASK,2\\)");
71: }
72:
73: public static void main(String[] args) {
74: RepeatHelper.runTests(args, JTableRecorderTest.class);
75: }
76: }
|