01: package abbot.tester;
02:
03: import java.awt.Dimension;
04:
05: import javax.swing.*;
06:
07: import junit.extensions.abbot.*;
08: import junit.framework.*;
09:
10: /** Unit test to verify the JTabbedPaneTester class.<p> */
11:
12: public class JTabbedPaneTesterTest extends ComponentTestFixture {
13:
14: private JTabbedPaneTester tester;
15: private JTabbedPane tabbedPane;
16: private final int MAX = 10;
17:
18: /** Create a new test case with the given name. */
19: public JTabbedPaneTesterTest(String name) {
20: super (name);
21: }
22:
23: protected void setUp() {
24: tester = (JTabbedPaneTester) ComponentTester
25: .getTester(JTabbedPane.class);
26: tabbedPane = new JTabbedPane();
27: for (int i = 0; i < MAX; i++) {
28: tabbedPane.addTab("Tab " + i, new JLabel("Pane #" + i) {
29: public Dimension getPreferredSize() {
30: return new Dimension(300, 175);
31: }
32: });
33: }
34: }
35:
36: public void testSelectTabByIndex() {
37: showFrame(tabbedPane);
38: for (int i = 0; i < MAX; i++) {
39: tester.actionSelectTab(tabbedPane, new JTabbedPaneLocation(
40: i));
41: assertEquals("Wrong tab selected", i, tabbedPane
42: .getSelectedIndex());
43: }
44: }
45:
46: public void testSelectTabByName() {
47: showFrame(tabbedPane);
48: for (int i = 0; i < MAX; i++) {
49: String title = "Tab " + i;
50: tester.actionSelectTab(tabbedPane, new JTabbedPaneLocation(
51: title));
52: assertEquals("Wrong tab selected", title, tabbedPane
53: .getTitleAt(tabbedPane.getSelectedIndex()));
54: }
55: }
56:
57: /** Return the default test suite. */
58: public static Test suite() {
59: return new TestSuite(JTabbedPaneTesterTest.class);
60: }
61:
62: public static void main(String[] args) {
63: RepeatHelper.runTests(args, JTabbedPaneTesterTest.class);
64: }
65: }
|