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