01: package abbot.tester;
02:
03: import java.awt.TextField;
04: import java.awt.TextComponent;
05:
06: import junit.extensions.abbot.*;
07:
08: /** Unit test to verify the TextComponentTester class.<p> */
09:
10: public class TextComponentTesterTest extends ComponentTestFixture {
11:
12: private TextComponentTester tester;
13: private TextComponent tc;
14:
15: protected void setUp() {
16: TextField tf = new TextField();
17: tf.setColumns(10);
18: tc = tf;
19: tester = new TextComponentTester();
20: }
21:
22: /** Wholesale text replacement by typing. */
23: // FIXME sporadic w32 misses first character
24: public void testSetText() {
25: showFrame(tc);
26: String text = "short";
27: tester.actionEnterText(tc, text);
28: assertEquals("Wrong short text typed,", text, tc.getText());
29: text = "longer";
30: tester.actionEnterText(tc, text);
31: assertEquals("Wrong replacement text,", text, tc.getText());
32: text = "Some longer text that will surely exceed the field width";
33: tester.actionEnterText(tc, text);
34: assertEquals("Wrong long replacement text,", text, tc.getText());
35: text = "shorter";
36: tester.actionEnterText(tc, text);
37: assertEquals("Wrong shorter replacement text,", text, tc
38: .getText());
39:
40: }
41:
42: /** Verify we can select arbitrary bits of text. */
43: public void testSelect() {
44: showFrame(tc);
45: String text = "short";
46: tc.setText(text);
47: tester.waitForIdle();
48: tester.actionSelectText(tc, 0, text.length());
49: assertEquals("Wrong selection start (full)", 0, tc
50: .getSelectionStart());
51: assertEquals("Wrong selection end (full)", text.length(), tc
52: .getSelectionEnd());
53:
54: tester.actionSelectText(tc, 1, text.length() - 1);
55: assertEquals("Wrong selection start (mid)", 1, tc
56: .getSelectionStart());
57: assertEquals("Wrong selection end (mid)", text.length() - 1, tc
58: .getSelectionEnd());
59: }
60:
61: /** Select text that goes beyond the visible display area. */
62: public void testLongSelection() {
63: showFrame(tc);
64: String text = "The quick brown fox jumped over the lazy dog";
65: tc.setText(text);
66: tester.waitForIdle();
67: tester.actionSelectText(tc, 0, text.length());
68: assertEquals("Wrong selection start (full)", 0, tc
69: .getSelectionStart());
70: assertEquals("Wrong selection end, end hidden (full)", text
71: .length(), tc.getSelectionEnd());
72: tester.actionSelectText(tc, 1, text.length() - 1);
73: assertEquals("Wrong selection start, start hidden, (mid)", 1,
74: tc.getSelectionStart());
75: assertEquals("Wrong selection end (mid)", text.length() - 1, tc
76: .getSelectionEnd());
77: }
78:
79: /** Create a new test case with the given name. */
80: public TextComponentTesterTest(String name) {
81: super (name);
82: }
83:
84: public static void main(String[] args) {
85: RepeatHelper.runTests(args, TextComponentTesterTest.class);
86: }
87: }
|