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