Source Code Cross Referenced for JTabbedPaneTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Vadim L. Bogdanov
019:         * @version $Revision$
020:         */package javax.swing;
021:
022:        import java.awt.Color;
023:        import java.awt.Component;
024:        import java.awt.Rectangle;
025:        import java.awt.event.KeyEvent;
026:        import java.awt.event.MouseEvent;
027:        import java.beans.PropertyChangeEvent;
028:        import java.beans.PropertyChangeListener;
029:        import java.util.Arrays;
030:        import javax.swing.event.ChangeEvent;
031:        import javax.swing.event.ChangeListener;
032:        import javax.swing.plaf.ComponentUI;
033:        import javax.swing.plaf.UIResource;
034:        import javax.swing.plaf.basic.BasicIconFactory;
035:        import javax.swing.plaf.basic.BasicTabbedPaneUI;
036:
037:        public class JTabbedPaneTest extends SwingTestCase {
038:            private class MyChangeListener implements  ChangeListener {
039:                public boolean eventFired;
040:
041:                public ChangeEvent event;
042:
043:                public void stateChanged(final ChangeEvent e) {
044:                    eventFired = true;
045:                    event = e;
046:                }
047:            }
048:
049:            private class MyPropertyChangeListener implements 
050:                    PropertyChangeListener {
051:                public boolean eventFired;
052:
053:                public void propertyChange(final PropertyChangeEvent event) {
054:                    eventFired = true;
055:                }
056:            }
057:
058:            private static Icon someIcon = BasicIconFactory
059:                    .createEmptyFrameIcon();
060:
061:            private String tabTitle1 = "tab1";
062:
063:            private Icon tabIcon = null;
064:
065:            private JComponent tabComponent1 = new JPanel();
066:
067:            private String tabTip1 = "tip1";
068:
069:            private int tabIndex1 = 0;
070:
071:            private String tabTitle2 = "tab2";
072:
073:            private JComponent tabComponent2 = new JPanel();
074:
075:            private String tabTip2 = "tip2";
076:
077:            private JComponent tabComponent3 = new JPanel();
078:
079:            private JTabbedPane tabbed;
080:
081:            public JTabbedPaneTest(final String name) {
082:                super (name);
083:            }
084:
085:            /*
086:             * @see TestCase#setUp()
087:             */
088:            @Override
089:            protected void setUp() throws Exception {
090:                super .setUp();
091:                tabbed = new JTabbedPane();
092:                tabbed.setSize(100, 50);
093:                tabbed.insertTab(tabTitle1, tabIcon, tabComponent1, tabTip1,
094:                        tabIndex1);
095:                tabbed.insertTab(tabTitle2, tabIcon, tabComponent2, tabTip2,
096:                        tabIndex1);
097:                tabbed.insertTab(tabTitle1, tabIcon, tabComponent3, tabTip1, 0);
098:            }
099:
100:            /*
101:             * @see TestCase#tearDown()
102:             */
103:            @Override
104:            protected void tearDown() throws Exception {
105:                super .tearDown();
106:            }
107:
108:            public void testRemoveAll() {
109:                tabbed.removeAll();
110:                assertEquals("removed tabs", 0, tabbed.getTabCount());
111:                assertEquals("removed components", 0, tabbed
112:                        .getComponentCount());
113:                assertEquals("no selected component", -1, tabbed
114:                        .getSelectedIndex());
115:            }
116:
117:            public void testUpdateUI() {
118:                tabbed.updateUI();
119:                ComponentUI ui1 = tabbed.getUI();
120:                ComponentUI ui2 = UIManager.getUI(tabbed);
121:                // at least names of classes must be the same
122:                assertEquals(ui2.getClass().getName(), ui1.getClass().getName());
123:            }
124:
125:            public void testGetTabCount() {
126:                assertEquals(3, tabbed.getTabCount());
127:            }
128:
129:            public void testGetTabRunCount() {
130:                assertEquals(tabbed.getUI().getTabRunCount(tabbed), tabbed
131:                        .getTabRunCount());
132:                tabbed.setUI(null);
133:                assertEquals(0, tabbed.getTabRunCount());
134:            }
135:
136:            public void testFireStateChanged() {
137:                MyChangeListener l = new MyChangeListener();
138:                tabbed.addChangeListener(l);
139:                tabbed.fireStateChanged();
140:                assertTrue(l.eventFired);
141:                assertSame("source", tabbed, l.event.getSource());
142:            }
143:
144:            public void testJTabbedPane() {
145:                tabbed = new JTabbedPane();
146:                assertEquals("placement", SwingConstants.TOP, tabbed
147:                        .getTabPlacement());
148:                assertEquals("tabLayout", JTabbedPane.WRAP_TAB_LAYOUT, tabbed
149:                        .getTabLayoutPolicy());
150:                assertTrue("ui != null", tabbed.getUI() != null);
151:                assertEquals("empty", 0, tabbed.getTabCount());
152:            }
153:
154:            public void testJTabbedPaneint() {
155:                tabbed = new JTabbedPane(SwingConstants.BOTTOM);
156:                assertEquals("placement", SwingConstants.BOTTOM, tabbed
157:                        .getTabPlacement());
158:                assertEquals("tabLayout", JTabbedPane.WRAP_TAB_LAYOUT, tabbed
159:                        .getTabLayoutPolicy());
160:            }
161:
162:            public void testJTabbedPaneintint() {
163:                tabbed = new JTabbedPane(SwingConstants.RIGHT,
164:                        JTabbedPane.SCROLL_TAB_LAYOUT);
165:                assertEquals("placement", SwingConstants.RIGHT, tabbed
166:                        .getTabPlacement());
167:                assertEquals("tabLayout", JTabbedPane.SCROLL_TAB_LAYOUT, tabbed
168:                        .getTabLayoutPolicy());
169:            }
170:
171:            public void testRemoveTabAt() {
172:                int oldTabCount = tabbed.getTabCount();
173:                tabbed.removeTabAt(tabbed.indexOfComponent(tabComponent3));
174:                assertFalse("removed", tabbed.isAncestorOf(tabComponent3));
175:                assertTrue("visible", tabComponent3.isVisible());
176:                assertEquals("count -= 1", oldTabCount - 1, tabbed
177:                        .getTabCount());
178:            }
179:
180:            /*
181:             * Class under test for void remove(Component)
182:             */
183:            public void testRemoveComponent() {
184:                int oldTabCount = tabbed.getTabCount();
185:                tabbed.remove(new JLabel());
186:                assertEquals("count didn't change", oldTabCount, tabbed
187:                        .getTabCount());
188:                tabbed.remove((Component) null);
189:                assertEquals("count didn't change", oldTabCount, tabbed
190:                        .getTabCount());
191:                tabbed.remove(tabComponent3);
192:                assertFalse("removed", tabbed.isAncestorOf(tabComponent3));
193:                assertTrue("visible", tabComponent3.isVisible());
194:                assertEquals("count -= 1", oldTabCount - 1, tabbed
195:                        .getTabCount());
196:            }
197:
198:            /*
199:             * Class under test for void remove(int)
200:             */
201:            public void testRemoveint() {
202:                int oldTabCount = tabbed.getTabCount();
203:                tabbed.remove(tabbed.indexOfComponent(tabComponent3));
204:                assertFalse("removed", tabbed.isAncestorOf(tabComponent3));
205:                assertTrue("visible", tabComponent3.isVisible());
206:                assertEquals("count -= 1", oldTabCount - 1, tabbed
207:                        .getTabCount());
208:            }
209:
210:            public void testSetGetSelectedIndex() {
211:                assertEquals("0 by default", 2, tabbed.getSelectedIndex());
212:                assertFalse("invisible", tabbed.getComponentAt(1).isVisible());
213:                tabbed.setSelectedIndex(1);
214:                assertFalse("invisible", tabbed.getComponentAt(0).isVisible());
215:                assertEquals("set to 1", 1, tabbed.getSelectedIndex());
216:                assertEquals("set in model", 1, tabbed.getModel()
217:                        .getSelectedIndex());
218:                if (isHarmony()) {
219:                    assertTrue("visible", tabbed.getSelectedComponent()
220:                            .isVisible());
221:                }
222:                boolean caught = false;
223:                try {
224:                    tabbed.setSelectedIndex(100);
225:                } catch (IndexOutOfBoundsException e) {
226:                    caught = true;
227:                }
228:                assertTrue("caught", caught);
229:                tabbed = new JTabbedPane();
230:                assertEquals("no selection", -1, tabbed.getSelectedIndex());
231:            }
232:
233:            public void testSetGetTabLayoutPolicy() {
234:                assertEquals("default", JTabbedPane.WRAP_TAB_LAYOUT, tabbed
235:                        .getTabLayoutPolicy());
236:                MyPropertyChangeListener l = new MyPropertyChangeListener();
237:                tabbed.addPropertyChangeListener("tabLayoutPolicy", l);
238:                tabbed.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
239:                assertEquals("set", JTabbedPane.SCROLL_TAB_LAYOUT, tabbed
240:                        .getTabLayoutPolicy());
241:                assertTrue(l.eventFired);
242:                boolean caught = false;
243:                try {
244:                    tabbed.setTabLayoutPolicy(-4);
245:                } catch (IllegalArgumentException e) {
246:                    caught = true;
247:                }
248:                assertTrue("IllegalArgumentException", caught);
249:            }
250:
251:            public void testSetGetTabPlacement() {
252:                assertEquals("default", SwingConstants.TOP, tabbed
253:                        .getTabPlacement());
254:                MyPropertyChangeListener l = new MyPropertyChangeListener();
255:                tabbed.addPropertyChangeListener("tabPlacement", l);
256:                tabbed.setTabPlacement(SwingConstants.LEFT);
257:                assertEquals("set", SwingConstants.LEFT, tabbed
258:                        .getTabPlacement());
259:                assertTrue(l.eventFired);
260:                boolean caught = false;
261:                try {
262:                    tabbed.setTabPlacement(-4);
263:                } catch (IllegalArgumentException e) {
264:                    caught = true;
265:                }
266:                assertTrue("IllegalArgumentException", caught);
267:            }
268:
269:            public void testIndexAtLocation() {
270:                int x = 2;
271:                int y = 2;
272:                assertEquals(tabbed.getUI().tabForCoordinate(tabbed, x, y),
273:                        tabbed.indexAtLocation(x, y));
274:                tabbed.setUI(null);
275:                assertEquals(-1, tabbed.indexAtLocation(x, y));
276:            }
277:
278:            public void testSetGetDisplayedMnemonicIndexAt() {
279:                assertEquals(-1, tabbed.getDisplayedMnemonicIndexAt(0));
280:                tabbed.setDisplayedMnemonicIndexAt(0, 1);
281:                assertEquals(1, tabbed.getDisplayedMnemonicIndexAt(0));
282:            }
283:
284:            public void testSetGetMnemonicAt() {
285:                assertEquals(-1, tabbed.getMnemonicAt(1));
286:                tabbed.setMnemonicAt(1, KeyEvent.VK_X);
287:                assertEquals(KeyEvent.VK_X, tabbed.getMnemonicAt(1));
288:            }
289:
290:            public void testSetIsEnabledAt() {
291:                assertTrue("by default", tabbed.isEnabledAt(1));
292:                tabbed.setEnabledAt(1, false);
293:                assertFalse("set to false", tabbed.isEnabledAt(1));
294:                tabbed.setEnabledAt(1, true);
295:                assertTrue("set to true", tabbed.isEnabledAt(1));
296:            }
297:
298:            /*
299:             * Class under test for Component add(Component)
300:             */
301:            public void testAddComponent() {
302:                JComponent comp = new JLabel("label");
303:                comp.setName("label");
304:                Component result = tabbed.add(comp);
305:                assertEquals("result", comp, result);
306:                assertEquals("index", 3, tabbed.indexOfComponent(comp));
307:                assertEquals("title", "label", tabbed.getTitleAt(3));
308:                assertNull("tip", tabbed.getToolTipTextAt(3));
309:                class UIResourceButton extends JButton implements  UIResource {
310:                    private static final long serialVersionUID = 1L;
311:                }
312:                int tabCount = tabbed.getTabCount();
313:                comp = new UIResourceButton();
314:                result = tabbed.add(comp);
315:                assertSame(comp, result);
316:                assertEquals("no new tab for UIResource", tabCount, tabbed
317:                        .getTabCount());
318:            }
319:
320:            /*
321:             * Class under test for Component add(Component, int)
322:             */
323:            public void testAddComponentint() {
324:                JComponent comp = new JLabel("label");
325:                comp.setName("label");
326:                Component result = tabbed.add(comp, 2);
327:                assertEquals("result", comp, result);
328:                assertEquals("index", 2, tabbed.indexOfComponent(comp));
329:                assertEquals("title", "label", tabbed.getTitleAt(2));
330:                assertNull("tip", tabbed.getToolTipTextAt(2));
331:            }
332:
333:            /*
334:             * Class under test for void add(Component, Object)
335:             */
336:            public void testAddComponentObject() {
337:                int index = 3;
338:                JComponent comp = new JLabel("label");
339:                comp.setName("labelName");
340:                Object constraints = "label";
341:                tabbed.add(comp, constraints);
342:                assertEquals("index", index, tabbed.indexOfComponent(comp));
343:                assertEquals("title", constraints, tabbed.getTitleAt(index));
344:                tabbed.remove(comp);
345:                comp = new JLabel("label");
346:                comp.setName("labelName");
347:                constraints = someIcon;
348:                tabbed.add(comp, constraints);
349:                assertEquals("title", "", tabbed.getTitleAt(index));
350:                assertEquals("icon", constraints, tabbed.getIconAt(index));
351:                tabbed.remove(comp);
352:                comp = new JLabel("label");
353:                comp.setName("labelName");
354:                constraints = new Integer(3); // just some Object
355:                tabbed.add(comp, constraints);
356:                assertEquals("title", "labelName", tabbed.getTitleAt(tabbed
357:                        .indexOfComponent(comp)));
358:                assertNull("icon", tabbed.getIconAt(tabbed
359:                        .indexOfComponent(comp)));
360:                tabbed.remove(comp);
361:            }
362:
363:            /*
364:             * Class under test for void add(Component, Object, int)
365:             */
366:            public void testAddComponentObjectint() {
367:                int index = 2;
368:                JComponent comp = new JLabel("label");
369:                comp.setName("labelName");
370:                Object constraints = "label";
371:                tabbed.add(comp, constraints, index);
372:                assertEquals("index", index, tabbed.indexOfComponent(comp));
373:                assertEquals("title", constraints, tabbed.getTitleAt(index));
374:                tabbed.remove(comp);
375:                comp = new JLabel("label");
376:                comp.setName("labelName");
377:                constraints = BasicIconFactory.createEmptyFrameIcon(); // just some icon
378:                tabbed.add(comp, constraints, index);
379:                assertEquals("title", "", tabbed.getTitleAt(index));
380:                assertEquals("icon", constraints, tabbed.getIconAt(index));
381:                tabbed.remove(comp);
382:                comp = new JLabel("label");
383:                comp.setName("labelName");
384:                constraints = new Integer(3); // just some Object
385:                tabbed.add(comp, constraints, 1);
386:                if (BasicSwingTestCase.isHarmony()) {
387:                    assertEquals("title", "labelName", tabbed.getTitleAt(tabbed
388:                            .indexOfComponent(comp)));
389:                }
390:                assertNull("icon", tabbed.getIconAt(tabbed
391:                        .indexOfComponent(comp)));
392:                tabbed.remove(comp);
393:            }
394:
395:            /*
396:             * Class under test for Component add(String, Component)
397:             */
398:            public void testAddStringComponent() {
399:                JComponent comp = new JLabel("label");
400:                Component result = tabbed.add("label", comp);
401:                assertEquals("result", comp, result);
402:                assertEquals("index", 3, tabbed.indexOfComponent(comp));
403:                assertEquals("title", "label", tabbed.getTitleAt(3));
404:                assertNull("tip", tabbed.getToolTipTextAt(3));
405:            }
406:
407:            /*
408:             * Class under test for void addChangeListener(ChangeListener)
409:             */
410:            public void testAddRemoveChangeListener() {
411:                ChangeListener l = new MyChangeListener();
412:                int len = tabbed.getChangeListeners().length;
413:                tabbed.addChangeListener(l);
414:                assertEquals("added", len + 1,
415:                        tabbed.getChangeListeners().length);
416:                tabbed.removeChangeListener(l);
417:                assertEquals("removed", len, tabbed.getChangeListeners().length);
418:                tabbed.addChangeListener(null);
419:                assertEquals("adding null: no action", len, tabbed
420:                        .getChangeListeners().length);
421:                tabbed.removeChangeListener(null);
422:                assertEquals("removing null: no action", len, tabbed
423:                        .getChangeListeners().length);
424:            }
425:
426:            /*
427:             * Class under test for void addTab(String, Component)
428:             */
429:            public void testAddTabStringComponent() {
430:                JComponent comp = new JLabel("label");
431:                tabbed.addTab("label", comp);
432:                assertEquals("index", 3, tabbed.indexOfComponent(comp));
433:                assertEquals("title", "label", tabbed.getTitleAt(3));
434:                assertNull("tip", tabbed.getToolTipTextAt(3));
435:            }
436:
437:            /*
438:             * Class under test for void addTab(String, Icon, Component)
439:             */
440:            public void testAddTabStringIconComponent() {
441:                JComponent comp = new JLabel("label");
442:                tabbed.addTab("label", someIcon, comp);
443:                assertEquals("index", 3, tabbed.indexOfComponent(comp));
444:                assertEquals("title", "label", tabbed.getTitleAt(3));
445:                assertEquals("icon", someIcon, tabbed.getIconAt(3));
446:                assertNull("tip", tabbed.getToolTipTextAt(3));
447:            }
448:
449:            /*
450:             * Class under test for void addTab(String, Icon, Component, String)
451:             */
452:            public void testAddTabStringIconComponentString() {
453:                JComponent comp = new JLabel("label");
454:                tabbed.addTab("label", someIcon, comp, "tip");
455:                assertEquals("index", 3, tabbed.indexOfComponent(comp));
456:                assertEquals("title", "label", tabbed.getTitleAt(3));
457:                assertEquals("icon", someIcon, tabbed.getIconAt(3));
458:                assertEquals("tip", "tip", tabbed.getToolTipTextAt(3));
459:            }
460:
461:            /*
462:             * Class under test for ChangeListener createChangeListener()
463:             */
464:            public void testCreateChangeListener() {
465:                ChangeListener l1 = tabbed.createChangeListener();
466:                assertNotNull("not null", l1);
467:                assertNotSame("not same", l1, tabbed.changeListener);
468:            }
469:
470:            /*
471:             * Class under test for AccessibleContext getAccessibleContext()
472:             */
473:            public void testGetAccessibleContext() {
474:                assertTrue(tabbed.getAccessibleContext() instanceof  JTabbedPane.AccessibleJTabbedPane);
475:            }
476:
477:            /*
478:             * Class under test for Rectangle getBoundsAt(int)
479:             */
480:            public void testGetBoundsAt() {
481:                assertEquals(tabbed.getBoundsAt(1), tabbed.getUI()
482:                        .getTabBounds(tabbed, 1));
483:                tabbed.setUI(null);
484:                assertNull(tabbed.getBoundsAt(1));
485:            }
486:
487:            /*
488:             * Class under test for ChangeListener[] getChangeListeners()
489:             */
490:            public void testGetChangeListeners() {
491:                tabbed.setUI(null);
492:                assertEquals("empty array", 0,
493:                        tabbed.getChangeListeners().length);
494:                tabbed.addChangeListener(new MyChangeListener());
495:                assertEquals("1 element", 1, tabbed.getChangeListeners().length);
496:            }
497:
498:            /*
499:             * Class under test for void setTitleAt(int, String)
500:             */
501:            public void testSetTitleAt() {
502:                String newTitle = "newTitle";
503:                tabbed.setTitleAt(1, newTitle);
504:                assertEquals("newTitle is set", newTitle, tabbed.getTitleAt(1));
505:                boolean catched = false;
506:                try {
507:                    tabbed.setTitleAt(-1, newTitle);
508:                } catch (IndexOutOfBoundsException e) {
509:                    catched = true;
510:                }
511:                assertTrue("IndexOutOfBoundsException: index < 0", catched);
512:                catched = false;
513:                try {
514:                    tabbed.setTitleAt(tabbed.getTabCount(), newTitle);
515:                } catch (IndexOutOfBoundsException e) {
516:                    catched = true;
517:                }
518:                assertTrue("IndexOutOfBoundsException: index >= tab count",
519:                        catched);
520:            }
521:
522:            /*
523:             * Class under test for String getTitleAt(int)
524:             */
525:            public void testGetTitleAt() {
526:                assertEquals("title1", tabTitle1, tabbed.getTitleAt(0));
527:                assertEquals("title2", tabTitle2, tabbed.getTitleAt(1));
528:                assertEquals("title1_2", tabTitle1, tabbed.getTitleAt(2));
529:                boolean catched = false;
530:                try {
531:                    tabbed.getTitleAt(-1);
532:                } catch (IndexOutOfBoundsException e) {
533:                    catched = true;
534:                }
535:                assertTrue("IndexOutOfBoundsException: index < 0", catched);
536:                catched = false;
537:                try {
538:                    tabbed.getTitleAt(tabbed.getTabCount());
539:                } catch (IndexOutOfBoundsException e) {
540:                    catched = true;
541:                }
542:                assertTrue("IndexOutOfBoundsException: index >= tab count",
543:                        catched);
544:            }
545:
546:            /*
547:             * Class under test for String getToolTipText(MouseEvent)
548:             */
549:            public void testGetToolTipTextMouseEvent() {
550:                Rectangle bounds = tabbed.getBoundsAt(1);
551:                tabbed.setToolTipTextAt(1, "tooltip");
552:                MouseEvent e = new MouseEvent(tabbed, MouseEvent.MOUSE_MOVED,
553:                        0L, 0, bounds.x + 1, bounds.y + 1, 1, false);
554:                assertEquals("tooltip", tabbed.getToolTipText(e));
555:                e = new MouseEvent(tabbed, MouseEvent.MOUSE_MOVED, 0L, 0,
556:                        Short.MAX_VALUE, Short.MAX_VALUE, 1, false);
557:                assertNull(tabbed.getToolTipText(e));
558:            }
559:
560:            /*
561:             * Class under test for String getUIClassID()
562:             */
563:            public void testGetUIClassID() {
564:                assertEquals("uiClassID", "TabbedPaneUI", tabbed.getUIClassID());
565:            }
566:
567:            /*
568:             * Class under test for int indexOfComponent(Component)
569:             */
570:            public void testIndexOfComponent() {
571:                assertEquals("index of null", -1, tabbed.indexOfComponent(null));
572:                tabbed.setComponentAt(2, tabComponent1);
573:                assertEquals("comp1", 2, tabbed.indexOfComponent(tabComponent1));
574:            }
575:
576:            /*
577:             * Class under test for int indexOfTab(Icon)
578:             */
579:            public void testIndexOfTabIcon() {
580:                Icon otherIcon = BasicIconFactory.getCheckBoxIcon();
581:                assertEquals("index of null", 0, tabbed.indexOfTab((Icon) null));
582:                tabbed.setIconAt(1, someIcon);
583:                assertEquals(1, tabbed.indexOfTab(someIcon));
584:                assertEquals("no icon", -1, tabbed.indexOfTab(otherIcon));
585:            }
586:
587:            /*
588:             * Class under test for int indexOfTab(String)
589:             */
590:            public void testIndexOfTabString() {
591:                assertEquals("index of null", -1, tabbed
592:                        .indexOfTab((String) null));
593:                tabbed.setTitleAt(1, "someTitle");
594:                assertEquals(1, tabbed.indexOfTab("someTitle"));
595:                assertEquals("no icon", -1, tabbed.indexOfTab("otherTitle"));
596:            }
597:
598:            public void testInsertTab() {
599:                tabbed.removeAll();
600:                tabbed = new JTabbedPane();
601:                assertEquals(-1, tabbed.getSelectedIndex());
602:                tabbed.insertTab(tabTitle1, tabIcon, tabComponent1, tabTip1, 0);
603:                assertEquals(0, tabbed.getSelectedIndex());
604:                tabbed.insertTab(tabTitle2, tabIcon, tabComponent2, tabTip2, 0);
605:                assertEquals(2, tabbed.getTabCount());
606:                assertEquals(1, tabbed.getSelectedIndex());
607:                assertSame(tabComponent1, tabbed.getComponent(0));
608:                assertSame(tabComponent2, tabbed.getComponent(1));
609:                assertSame(tabComponent2, tabbed.getComponentAt(0));
610:                assertSame(tabComponent1, tabbed.getComponentAt(1));
611:                assertEquals(1, tabbed.indexOfComponent(tabComponent1));
612:                assertEquals(0, tabbed.indexOfComponent(tabComponent2));
613:                assertEquals("title1", tabbed.getTitleAt(1), tabTitle1);
614:                assertEquals("component1", tabbed.getComponentAt(1),
615:                        tabComponent1);
616:                assertEquals("tip1", tabbed.getToolTipTextAt(1), tabTip1);
617:                if (isHarmony()) {
618:                    assertTrue("component1.isVisible()", tabComponent1
619:                            .isVisible());
620:                } else {
621:                    assertFalse("component1.isVisible()", tabComponent1
622:                            .isVisible());
623:                }
624:                assertNotNull("background", tabbed.getBackgroundAt(1));
625:                assertNotNull("foreground", tabbed.getForegroundAt(1));
626:                assertEquals("title2", tabbed.getTitleAt(0), tabTitle2);
627:                assertEquals("component2", tabbed.getComponentAt(0),
628:                        tabComponent2);
629:                assertEquals("tip2", tabbed.getToolTipTextAt(0), tabTip2);
630:                assertFalse("component2.isVisible()", tabComponent2.isVisible());
631:                tabbed.insertTab(tabTitle1, tabIcon, tabComponent3, tabTip1, 2);
632:                assertSame(tabComponent1, tabbed.getComponent(0));
633:                assertSame(tabComponent2, tabbed.getComponent(1));
634:                assertSame(tabComponent3, tabbed.getComponent(2));
635:                assertSame(tabComponent2, tabbed.getComponentAt(0));
636:                assertSame(tabComponent1, tabbed.getComponentAt(1));
637:                assertSame(tabComponent3, tabbed.getComponentAt(2));
638:                assertEquals(1, tabbed.indexOfComponent(tabComponent1));
639:                assertEquals(0, tabbed.indexOfComponent(tabComponent2));
640:                assertEquals(2, tabbed.indexOfComponent(tabComponent3));
641:                assertEquals(1, tabbed.getSelectedIndex());
642:                assertEquals(3, tabbed.getTabCount());
643:                assertFalse(tabComponent3.isVisible());
644:                tabbed.insertTab(tabTitle1, tabIcon, tabComponent3, tabTip1, 0);
645:                assertSame(tabComponent1, tabbed.getComponent(0));
646:                assertSame(tabComponent2, tabbed.getComponent(1));
647:                assertSame(tabComponent3, tabbed.getComponent(2));
648:                assertSame(tabComponent3, tabbed.getComponentAt(0));
649:                assertSame(tabComponent2, tabbed.getComponentAt(1));
650:                assertSame(tabComponent1, tabbed.getComponentAt(2));
651:                assertEquals(2, tabbed.indexOfComponent(tabComponent1));
652:                assertEquals(1, tabbed.indexOfComponent(tabComponent2));
653:                assertEquals(0, tabbed.indexOfComponent(tabComponent3));
654:                assertEquals(2, tabbed.getSelectedIndex());
655:                assertEquals(3, tabbed.getTabCount());
656:                tabbed.insertTab(null, tabIcon, tabComponent3, tabTip1, 0);
657:                assertSame(tabComponent1, tabbed.getComponent(0));
658:                assertSame(tabComponent2, tabbed.getComponent(1));
659:                assertSame(tabComponent3, tabbed.getComponent(2));
660:                assertSame(tabComponent3, tabbed.getComponentAt(0));
661:                assertSame(tabComponent2, tabbed.getComponentAt(1));
662:                assertSame(tabComponent1, tabbed.getComponentAt(2));
663:                assertEquals(2, tabbed.indexOfComponent(tabComponent1));
664:                assertEquals(1, tabbed.indexOfComponent(tabComponent2));
665:                assertEquals(0, tabbed.indexOfComponent(tabComponent3));
666:                assertEquals(2, tabbed.getSelectedIndex());
667:                assertEquals("tabCount == 2", 3, tabbed.getTabCount());
668:                assertEquals("title is empty, not null", "", tabbed
669:                        .getTitleAt(0));
670:                JButton tabComponent4 = new JButton();
671:                tabbed.insertTab(null, tabIcon, tabComponent4, tabTip1, 1);
672:                assertSame(tabComponent1, tabbed.getComponent(0));
673:                assertSame(tabComponent2, tabbed.getComponent(1));
674:                assertSame(tabComponent3, tabbed.getComponent(2));
675:                assertSame(tabComponent4, tabbed.getComponent(3));
676:                assertSame(tabComponent3, tabbed.getComponentAt(0));
677:                assertSame(tabComponent4, tabbed.getComponentAt(1));
678:                assertSame(tabComponent2, tabbed.getComponentAt(2));
679:                assertSame(tabComponent1, tabbed.getComponentAt(3));
680:                assertEquals(3, tabbed.indexOfComponent(tabComponent1));
681:                assertEquals(2, tabbed.indexOfComponent(tabComponent2));
682:                assertEquals(1, tabbed.indexOfComponent(tabComponent4));
683:                assertEquals(0, tabbed.indexOfComponent(tabComponent3));
684:                assertEquals(3, tabbed.getSelectedIndex());
685:            }
686:
687:            /*
688:             * Class under test for String paramString()
689:             */
690:            public void testParamString() {
691:                String paramString = tabbed.paramString();
692:                assertNotNull(paramString);
693:                assertFalse("".equals(paramString));
694:            }
695:
696:            /*
697:             * Class under test for void setBackgroundAt(int, Color)
698:             */
699:            public void testSetBackgroundAt() {
700:                tabbed.setBackgroundAt(1, Color.RED);
701:                assertEquals(Color.RED, tabbed.getBackgroundAt(1));
702:                tabbed.setBackgroundAt(1, null);
703:                assertEquals("not null", tabbed.getBackground(), tabbed
704:                        .getBackgroundAt(1));
705:            }
706:
707:            /*
708:             * Class under test for Color getBackgroundAt(int)
709:             */
710:            public void testGetBackgroundAt() {
711:                assertTrue("instanceof UIResource",
712:                        tabbed.getBackgroundAt(1) instanceof  UIResource);
713:            }
714:
715:            /*
716:             * Class under test for void setForegroundAt(int, Color)
717:             */
718:            public void testSetForegroundAt() {
719:                tabbed.setForegroundAt(1, Color.RED);
720:                assertEquals(Color.RED, tabbed.getForegroundAt(1));
721:                tabbed.setForegroundAt(1, null);
722:                assertEquals("not null", tabbed.getForeground(), tabbed
723:                        .getForegroundAt(1));
724:            }
725:
726:            /*
727:             * Class under test for Color getForegroundAt(int)
728:             */
729:            public void testGetForegroundAt() {
730:                assertTrue("instanceof UIResource",
731:                        tabbed.getForegroundAt(1) instanceof  UIResource);
732:            }
733:
734:            public void testSetGetComponentAt() {
735:                JComponent newComp = new JLabel("new");
736:                int tabCount = tabbed.getTabCount();
737:                int index = tabbed.indexOfComponent(tabComponent2);
738:                assertSame(tabComponent1, tabbed.getComponent(0));
739:                assertSame(tabComponent2, tabbed.getComponent(1));
740:                assertSame(tabComponent3, tabbed.getComponent(2));
741:                assertSame(tabComponent3, tabbed.getComponentAt(0));
742:                assertSame(tabComponent2, tabbed.getComponentAt(1));
743:                assertSame(tabComponent1, tabbed.getComponentAt(2));
744:                assertEquals(2, tabbed.indexOfComponent(tabComponent1));
745:                assertEquals(1, tabbed.indexOfComponent(tabComponent2));
746:                assertEquals(0, tabbed.indexOfComponent(tabComponent3));
747:                tabbed.setComponentAt(index, newComp);
748:                assertSame(tabComponent1, tabbed.getComponent(0));
749:                assertSame(tabComponent3, tabbed.getComponent(1));
750:                assertSame(newComp, tabbed.getComponent(2));
751:                assertSame(tabComponent3, tabbed.getComponentAt(0));
752:                assertSame(newComp, tabbed.getComponentAt(1));
753:                assertSame(tabComponent1, tabbed.getComponentAt(2));
754:                assertEquals(2, tabbed.indexOfComponent(tabComponent1));
755:                assertEquals(1, tabbed.indexOfComponent(newComp));
756:                assertEquals(0, tabbed.indexOfComponent(tabComponent3));
757:                assertEquals(-1, tabbed.indexOfComponent(tabComponent2));
758:                assertEquals("tabCount", tabCount, tabbed.getTabCount());
759:                assertSame("component", newComp, tabbed.getComponentAt(index));
760:                assertFalse("newComp is not visible", newComp.isVisible());
761:                tabbed.setComponentAt(index, tabComponent3);
762:                assertSame(tabComponent1, tabbed.getComponent(0));
763:                assertSame(tabComponent3, tabbed.getComponent(1));
764:                assertSame(tabComponent3, tabbed.getComponentAt(0));
765:                assertSame(tabComponent1, tabbed.getComponentAt(1));
766:                assertEquals(0, tabbed.indexOfComponent(tabComponent3));
767:                assertEquals(1, tabbed.indexOfComponent(tabComponent1));
768:                assertEquals("tabCount - 1", tabCount - 1, tabbed.getTabCount());
769:                assertEquals("visibility", !BasicSwingTestCase.isHarmony(),
770:                        tabComponent3.isVisible());
771:            }
772:
773:            public void testSetGetDisabledIconAt() {
774:                assertNull(tabbed.getDisabledIconAt(0));
775:                tabbed.setDisabledIconAt(0, someIcon);
776:                assertSame(someIcon, tabbed.getDisabledIconAt(0));
777:            }
778:
779:            public void testSetGetIconAt() {
780:                tabbed.setIconAt(1, someIcon);
781:                assertEquals(someIcon, tabbed.getIconAt(1));
782:            }
783:
784:            public void testSetGetModel() {
785:                assertNotNull("default", tabbed.getModel());
786:                PropertyChangeController cont = new PropertyChangeController();
787:                tabbed.addPropertyChangeListener(cont);
788:                DefaultSingleSelectionModel model = new DefaultSingleSelectionModel();
789:                tabbed.setModel(model);
790:                assertEquals("set", model, tabbed.getModel());
791:                assertTrue("fired property change event", cont
792:                        .isChanged("model"));
793:                assertTrue("listener", Arrays.asList(
794:                        ((DefaultSingleSelectionModel) tabbed.getModel())
795:                                .getChangeListeners()).contains(
796:                        tabbed.changeListener));
797:                // set model with another selected index, no state change event is fired
798:                tabbed.setModel(null);
799:                MyChangeListener changeListener = new MyChangeListener();
800:                tabbed.addChangeListener(changeListener);
801:                model.setSelectedIndex(2);
802:                tabbed.setModel(model);
803:                assertFalse(changeListener.eventFired);
804:            }
805:
806:            public void testSetGetSelectedComponentComponent() {
807:                tabbed.setSelectedComponent(tabComponent2);
808:                assertSame(tabComponent2, tabbed.getSelectedComponent());
809:                assertEquals(tabbed.indexOfComponent(tabComponent2), tabbed
810:                        .getSelectedIndex());
811:                boolean caught = false;
812:                try {
813:                    tabbed.setSelectedComponent(new JLabel());
814:                } catch (final IllegalArgumentException e) {
815:                    caught = true;
816:                }
817:                assertTrue(caught);
818:            }
819:
820:            public void testSetGetToolTipTextAt() {
821:                JComponent comp = new JLabel();
822:                tabbed.add(comp);
823:                int index = tabbed.indexOfComponent(comp);
824:                assertNull("by default", tabbed.getToolTipTextAt(index));
825:                tabbed.setToolTipTextAt(index, "newTip");
826:                assertEquals("newTip", tabbed.getToolTipTextAt(index));
827:                tabbed.setToolTipTextAt(index, null);
828:                assertNull(tabbed.getToolTipTextAt(index));
829:            }
830:
831:            public void testSetGetUI() {
832:                BasicTabbedPaneUI ui = new BasicTabbedPaneUI();
833:                tabbed.setUI(ui);
834:                assertSame(ui, tabbed.getUI());
835:            }
836:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.