01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05:
06: import junit.extensions.abbot.*;
07:
08: public class ButtonTesterTest extends ComponentTestFixture {
09: public void testClickButton() {
10: final Button b = new Button(getName());
11: showFrame(b);
12: final String expected = "button clicked";
13: b.addActionListener(new ActionListener() {
14: public void actionPerformed(ActionEvent e) {
15: b.setLabel(expected);
16: }
17: });
18: ButtonTester tester = new ButtonTester();
19: tester.actionClick(b);
20: assertEquals("Button not clicked", expected, b.getLabel());
21: }
22:
23: public void testAWTModeButtonClick() {
24: int lastMode = Robot.getEventMode();
25: Robot.setEventMode(Robot.EM_AWT);
26: try {
27: final Button b = new Button(getName());
28: showFrame(b);
29: final String expected = "button clicked";
30: b.addActionListener(new ActionListener() {
31: public void actionPerformed(ActionEvent e) {
32: b.setLabel(expected);
33: }
34: });
35: getRobot().click(b);
36: getRobot().waitForIdle();
37: assertTrue("Expect Button to not be clickable in AWT mode",
38: !expected.equals(b.getLabel()));
39: } finally {
40: Robot.setEventMode(lastMode);
41: }
42: }
43:
44: public ButtonTesterTest(String name) {
45: super (name);
46: }
47:
48: public static void main(String[] args) {
49: TestHelper.runTests(args, ButtonTesterTest.class);
50: }
51:
52: }
|