01: package abbot.tester;
02:
03: import java.awt.*;
04: import java.awt.event.*;
05:
06: import junit.extensions.abbot.*;
07:
08: /** Unit test to verify the ListTester class.<p> */
09: public class ListTesterTest extends ComponentTestFixture {
10:
11: private ListTester tester;
12: private List list;
13:
14: private String[] data = { "zero", "one", "two", "three", "four",
15: "five", "six", "seven", "eight" };
16:
17: protected void setUp() {
18: tester = new ListTester();
19: list = new List(data.length);
20: for (int i = 0; i < data.length; i++) {
21: list.add(data[i]);
22: }
23: showFrame(list);
24: }
25:
26: public void testSelectRow() {
27: class Listener implements ItemListener {
28: int index = -1;
29: boolean selected;
30:
31: public void itemStateChanged(ItemEvent e) {
32: index = ((List) e.getSource()).getSelectedIndex();
33: selected = e.getStateChange() == ItemEvent.SELECTED;
34: }
35: }
36: Listener listener = new Listener();
37: list.addItemListener(listener);
38: for (int i = 0; i < data.length; i++) {
39: listener.selected = false;
40: tester.actionSelectRow(list, new ListLocation(i));
41: assertTrue("No select fired", listener.selected);
42: assertEquals("Incorrect selection", i, listener.index);
43: }
44: }
45:
46: /** Create a new test case with the given name. */
47: public ListTesterTest(String name) {
48: super (name);
49: }
50:
51: public static void main(String[] args) {
52: RepeatHelper.runTests(args, ListTesterTest.class);
53: }
54: }
|