01: package abbot.editor.widgets;
02:
03: import java.awt.event.*;
04: import junit.extensions.abbot.*;
05: import abbot.tester.*;
06:
07: public class TextFieldTest extends ComponentTestFixture {
08:
09: private TextField textField;
10: private JTextComponentTester tester;
11:
12: protected void setUp() {
13: tester = new JTextComponentTester();
14: textField = new TextField("Basic Field");
15: showFrame(textField);
16: }
17:
18: public void testReplaceText() {
19: tester.actionActionMap(textField, "select-all");
20: tester.actionKeyString("replaced");
21: String text = textField.getText();
22: assertEquals("Text not replaced", "replaced", text);
23: }
24:
25: public void testRevert() {
26: class Flag {
27: volatile boolean flag;
28: String command;
29: }
30: final Flag fired = new Flag();
31: String orig = textField.getText();
32: tester.actionEnterText(textField, "new text");
33: assertTrue("Text not entered", !textField.getText()
34: .equals(orig));
35: textField.addActionListener(new ActionListener() {
36: public void actionPerformed(ActionEvent e) {
37: fired.flag = true;
38: fired.command = e.getActionCommand();
39: }
40: });
41: tester.actionKeyStroke(textField, KeyEvent.VK_ESCAPE);
42: assertEquals("Text not reverted", orig, textField.getText());
43: assertTrue("No action fired on revert", fired.flag);
44: assertEquals("Wrong action command",
45: TextField.ACTION_TEXT_REVERTED, fired.command);
46: }
47:
48: public void testSelectAllOnEnter() {
49: String text = "new text";
50: tester.actionEnterText(textField, text);
51: tester.actionKeyStroke(textField, KeyEvent.VK_ENTER);
52: assertEquals("Text should be selected", text, textField
53: .getSelectedText());
54: }
55:
56: /** Construct a test case with the given name. */
57: public TextFieldTest(String name) {
58: super (name);
59: }
60:
61: /** Run the default test suite. */
62: public static void main(String[] args) {
63: TestHelper.runTests(args, TextFieldTest.class);
64: }
65: }
|