01: package abbot.tester;
02:
03: import java.awt.event.*;
04: import javax.swing.JTextField;
05:
06: import junit.extensions.abbot.*;
07:
08: /** Unit test to verify the JTextFieldTester class.<p> */
09:
10: public class JTextFieldTesterTest extends ComponentTestFixture {
11:
12: private JTextFieldTester tester;
13: private JTextField tf;
14: private Listener listener;
15:
16: private class Listener implements ActionListener {
17: private String actionCommand;
18: private String text;
19: private JTextField field;
20:
21: public Listener(JTextField f) {
22: this .field = f;
23: f.addActionListener(this );
24: }
25:
26: public void actionPerformed(ActionEvent e) {
27: actionCommand = e.getActionCommand();
28: text = field.getText();
29: }
30: }
31:
32: protected void setUp() {
33: tf = new JTextField(getName());
34: tf.setColumns(10);
35: tester = new JTextFieldTester();
36: listener = new Listener(tf);
37: }
38:
39: public void testActionCommitText() {
40: final String EXPECTED = "Some new text";
41: showFrame(tf);
42: tester.actionCommitText(tf, EXPECTED);
43: assertEquals("Text not entered", EXPECTED, tf.getText());
44: assertEquals("Notification didn't fire", EXPECTED,
45: listener.text);
46: }
47:
48: public void testActionCommit() {
49: showFrame(tf);
50: final String EXPECTED = tf.getText();
51: tester.actionCommit(tf);
52: assertEquals("Notification didn't fire", EXPECTED,
53: listener.text);
54: }
55:
56: public static void main(String[] args) {
57: RepeatHelper.runTests(args, JTextFieldTesterTest.class);
58: }
59: }
|