01: package abbot.tester;
02:
03: import java.awt.Choice;
04: import java.awt.event.*;
05:
06: import junit.extensions.abbot.*;
07:
08: /** Unit test to verify supported operations on the Choice class.<p> */
09:
10: public class ChoiceTesterTest extends ComponentTestFixture {
11:
12: private ChoiceTester tester;
13: private Choice choice;
14: private static final int MAX_ENTRIES = 100;
15:
16: private String selectedItem = null;
17: private int selectedIndex = -1;
18:
19: protected void setUp() {
20: tester = (ChoiceTester) ComponentTester.getTester(Choice.class);
21: choice = new Choice();
22: for (int i = 0; i < MAX_ENTRIES; i++) {
23: choice.add("item " + i);
24: }
25: choice.select(MAX_ENTRIES - 1);
26: choice.addItemListener(new ItemListener() {
27: public void itemStateChanged(ItemEvent ev) {
28: abbot.Log.debug("Got " + ev);
29: if (ev.getStateChange() == ItemEvent.SELECTED) {
30: selectedIndex = choice.getSelectedIndex();
31: selectedItem = choice.getItem(selectedIndex);
32: }
33: }
34: });
35: }
36:
37: public void testSelectIndex() {
38: showFrame(choice);
39: for (int i = 0; i < MAX_ENTRIES; i += MAX_ENTRIES / 10) {
40: selectedIndex = -1;
41: tester.actionSelectIndex(choice, i);
42: assertEquals("Listener not notified", i, selectedIndex);
43: assertEquals("Component state not properly set", i, choice
44: .getSelectedIndex());
45: }
46: }
47:
48: public void testSelectItem() {
49: showFrame(choice);
50: for (int i = 0; i < MAX_ENTRIES; i += MAX_ENTRIES / 10) {
51: selectedItem = null;
52: String item = "item " + i;
53: tester.actionSelectItem(choice, item);
54: assertEquals("Listener not notified", item, selectedItem);
55: assertEquals("Component state not properly set", item,
56: choice.getSelectedObjects()[0]);
57: }
58: }
59:
60: public static void main(String[] args) {
61: RepeatHelper.runTests(args, ChoiceTesterTest.class);
62: }
63: }
|