Source Code Cross Referenced for JMenuTest.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) 


0001:        /*
0002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
0003:         *  contributor license agreements.  See the NOTICE file distributed with
0004:         *  this work for additional information regarding copyright ownership.
0005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
0006:         *  (the "License"); you may not use this file except in compliance with
0007:         *  the License.  You may obtain a copy of the License at
0008:         *
0009:         *     http://www.apache.org/licenses/LICENSE-2.0
0010:         *
0011:         *  Unless required by applicable law or agreed to in writing, software
0012:         *  distributed under the License is distributed on an "AS IS" BASIS,
0013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014:         *  See the License for the specific language governing permissions and
0015:         *  limitations under the License.
0016:         */
0017:        /**
0018:         * @author Alexander T. Simbirtsev
0019:         * @version $Revision$
0020:         */package javax.swing;
0021:
0022:        import java.awt.Component;
0023:        import java.awt.ComponentOrientation;
0024:        import java.awt.Dimension;
0025:        import java.awt.Point;
0026:        import java.awt.event.ActionEvent;
0027:        import java.beans.PropertyChangeListener;
0028:        import java.util.EventListener;
0029:        import javax.swing.JPopupMenuTest.MyAction;
0030:        import javax.swing.event.MenuEvent;
0031:        import javax.swing.event.MenuListener;
0032:
0033:        @SuppressWarnings("serial")
0034:        public class JMenuTest extends JMenuItemTest {
0035:            class ConcreteMenuListener implements  MenuListener {
0036:                public Object event;
0037:
0038:                public Object src;
0039:
0040:                private final boolean debugOut;
0041:
0042:                ConcreteMenuListener() {
0043:                    debugOut = false;
0044:                }
0045:
0046:                ConcreteMenuListener(boolean debugOut) {
0047:                    this .debugOut = debugOut;
0048:                }
0049:
0050:                public void menuCanceled(MenuEvent e) {
0051:                    event = "canceled";
0052:                    src = e.getSource();
0053:                    if (debugOut) {
0054:                        System.out.println(event);
0055:                    }
0056:                }
0057:
0058:                public void menuDeselected(MenuEvent e) {
0059:                    event = "deselected";
0060:                    src = e.getSource();
0061:                    if (debugOut) {
0062:                        System.out.println(event);
0063:                    }
0064:                }
0065:
0066:                public void menuSelected(MenuEvent e) {
0067:                    event = "selected";
0068:                    src = e.getSource();
0069:                    if (debugOut) {
0070:                        System.out.println(event);
0071:                    }
0072:                }
0073:            };
0074:
0075:            protected JMenu menu;
0076:
0077:            private int menuOffsetX;
0078:
0079:            private int menuOffsetY;
0080:
0081:            private int submenuOffsetX;
0082:
0083:            private int submenuOffsetY;
0084:
0085:            @Override
0086:            protected void setUp() throws Exception {
0087:                super .setUp();
0088:                menu = new JMenu();
0089:                menuItem = menu;
0090:                button = menuItem;
0091:                menuOffsetX = UIManager.getInt("Menu.menuPopupOffsetX");
0092:                menuOffsetY = UIManager.getInt("Menu.menuPopupOffsetY");
0093:                submenuOffsetX = UIManager.getInt("Menu.submenuPopupOffsetX");
0094:                submenuOffsetY = UIManager.getInt("Menu.submenuPopupOffsetY");
0095:            }
0096:
0097:            @Override
0098:            protected void tearDown() throws Exception {
0099:                UIManager
0100:                        .put("Menu.menuPopupOffsetX", new Integer(menuOffsetX));
0101:                UIManager
0102:                        .put("Menu.menuPopupOffsetY", new Integer(menuOffsetY));
0103:                UIManager.put("Menu.submenuPopupOffsetX", new Integer(
0104:                        submenuOffsetX));
0105:                UIManager.put("Menu.submenuPopupOffsetY", new Integer(
0106:                        submenuOffsetY));
0107:                menu = null;
0108:                super .tearDown();
0109:            }
0110:
0111:            @Override
0112:            public void testJMenuItem() {
0113:            }
0114:
0115:            /*
0116:             * Test method for 'javax.swing.JMenu.JMenu()'
0117:             */
0118:            public void testJMenu() {
0119:                assertTrue("default buttonModel ",
0120:                        button.getModel() instanceof  DefaultButtonModel);
0121:                assertNull("icon ", button.getIcon());
0122:                assertEquals("text ", "", button.getText());
0123:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
0124:                assertTrue(menuItem.isFocusable());
0125:                assertEquals(menu, menuItem.getComponent());
0126:                assertEquals(0, menu.getItemCount());
0127:                assertEquals(0, menu.getMenuComponentCount());
0128:                assertNotNull(menu.getPopupMenu());
0129:                assertEquals(1, menu.getSubElements().length);
0130:                assertEquals(menu.getPopupMenu(), menu.getSubElements()[0]);
0131:                assertFalse(menu.isTopLevelMenu());
0132:                assertFalse(menu.isSelected());
0133:                assertEquals(200, menu.getDelay());
0134:                assertEquals(SwingConstants.LEADING, button
0135:                        .getHorizontalAlignment());
0136:                assertEquals(SwingConstants.TRAILING, button
0137:                        .getHorizontalTextPosition());
0138:                assertEquals(SwingConstants.CENTER, button
0139:                        .getVerticalAlignment());
0140:                assertEquals(SwingConstants.CENTER, button
0141:                        .getVerticalTextPosition());
0142:            }
0143:
0144:            /*
0145:             * Test method for 'javax.swing.JMenu.JMenu(String)'
0146:             */
0147:            public void testJMenuString() {
0148:                String text = "texttext";
0149:                button = menuItem = menu = new JMenu(text);
0150:                assertTrue("default buttonModel ",
0151:                        button.getModel() instanceof  DefaultButtonModel);
0152:                assertNull("icon ", button.getIcon());
0153:                assertEquals("text ", text, button.getText());
0154:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
0155:                assertEquals(menu, menuItem.getComponent());
0156:                assertEquals(0, menu.getItemCount());
0157:                assertEquals(0, menu.getMenuComponentCount());
0158:                assertNotNull(menu.getPopupMenu());
0159:                assertEquals(1, menu.getSubElements().length);
0160:                assertEquals(menu.getPopupMenu(), menu.getSubElements()[0]);
0161:                assertFalse(menu.isTopLevelMenu());
0162:                assertFalse(menu.isSelected());
0163:                assertTrue(menuItem.isFocusable());
0164:                assertEquals(200, menu.getDelay());
0165:                assertEquals(SwingConstants.LEADING, button
0166:                        .getHorizontalAlignment());
0167:                assertEquals(SwingConstants.TRAILING, button
0168:                        .getHorizontalTextPosition());
0169:                assertEquals(SwingConstants.CENTER, button
0170:                        .getVerticalAlignment());
0171:                assertEquals(SwingConstants.CENTER, button
0172:                        .getVerticalTextPosition());
0173:                button = menuItem = menu = new JMenu((String) null);
0174:                assertEquals("text ", "", button.getText());
0175:            }
0176:
0177:            /*
0178:             * Test method for 'javax.swing.JMenu.JMenu(String, boolean)'
0179:             */
0180:            public void testJMenuStringBoolean() {
0181:                String text = "texttext";
0182:                button = menuItem = menu = new JMenu(text, true);
0183:                assertTrue("default buttonModel ",
0184:                        button.getModel() instanceof  DefaultButtonModel);
0185:                assertNull("icon ", button.getIcon());
0186:                assertEquals("text ", text, button.getText());
0187:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
0188:                assertEquals(menu, menuItem.getComponent());
0189:                assertEquals(0, menu.getItemCount());
0190:                assertEquals(0, menu.getMenuComponentCount());
0191:                assertNotNull(menu.getPopupMenu());
0192:                assertEquals(1, menu.getSubElements().length);
0193:                assertEquals(menu.getPopupMenu(), menu.getSubElements()[0]);
0194:                assertFalse(menu.isTopLevelMenu());
0195:                assertFalse(menu.isSelected());
0196:                assertTrue(menuItem.isFocusable());
0197:                assertEquals(200, menu.getDelay());
0198:                assertEquals(SwingConstants.LEADING, button
0199:                        .getHorizontalAlignment());
0200:                assertEquals(SwingConstants.TRAILING, button
0201:                        .getHorizontalTextPosition());
0202:                assertEquals(SwingConstants.CENTER, button
0203:                        .getVerticalAlignment());
0204:                assertEquals(SwingConstants.CENTER, button
0205:                        .getVerticalTextPosition());
0206:                button = menuItem = menu = new JMenu((String) null, false);
0207:                assertEquals("text ", "", button.getText());
0208:            }
0209:
0210:            /*
0211:             * Test method for 'javax.swing.JMenu.JMenu(Action)'
0212:             */
0213:            public void testJMenuAction() {
0214:                final String command = "dnammoc";
0215:                class MyAction extends AbstractAction {
0216:                    public MyAction(final String text, final Icon icon) {
0217:                        super (text, icon);
0218:                        putValue(Action.ACTION_COMMAND_KEY, command);
0219:                    }
0220:
0221:                    public void actionPerformed(final ActionEvent e) {
0222:                    }
0223:                }
0224:                ;
0225:                Icon icon = createNewIcon();
0226:                String text = "texttext";
0227:                MyAction action = new MyAction(text, icon);
0228:                button = menuItem = menu = new JMenu(action);
0229:                assertEquals("icon ", icon, menuItem.getIcon());
0230:                assertEquals("text ", text, menuItem.getText());
0231:                assertEquals("action", action, menuItem.getAction());
0232:                assertEquals("command ", command, menuItem.getActionCommand());
0233:                assertFalse("selected ", menuItem.isSelected());
0234:                assertTrue("enabled ", menuItem.isEnabled());
0235:                assertNull("accelerator ", menuItem.getAccelerator());
0236:                assertTrue(menuItem.isFocusable());
0237:                assertEquals(200, menu.getDelay());
0238:                action.setEnabled(false);
0239:                button = menuItem = menu = new JMenu(action);
0240:                assertEquals("icon ", icon, menuItem.getIcon());
0241:                assertEquals("text ", text, menuItem.getText());
0242:                assertEquals("action", action, menuItem.getAction());
0243:                assertEquals("command ", command, menuItem.getActionCommand());
0244:                assertFalse("selected ", menuItem.isSelected());
0245:                assertFalse("enabled ", menuItem.isEnabled());
0246:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
0247:                button = menuItem = menu = new JMenu((Action) null);
0248:                assertNull("icon ", menuItem.getIcon());
0249:                assertNull("text ", menuItem.getText());
0250:                assertNull("action", menuItem.getAction());
0251:                assertNull("command ", menuItem.getActionCommand());
0252:                assertFalse("selected ", menuItem.isSelected());
0253:                assertTrue("enabled ", menuItem.isEnabled());
0254:                assertEquals(menu, menuItem.getComponent());
0255:                assertEquals(0, menu.getItemCount());
0256:                assertEquals(0, menu.getMenuComponentCount());
0257:                assertNotNull(menu.getPopupMenu());
0258:                assertEquals(1, menu.getSubElements().length);
0259:                assertEquals(menu.getPopupMenu(), menu.getSubElements()[0]);
0260:                assertFalse(menu.isTopLevelMenu());
0261:                assertFalse(menu.isSelected());
0262:                assertTrue("menuItem model is of the proper type", menuItem
0263:                        .getModel() instanceof  DefaultButtonModel);
0264:                assertEquals(SwingConstants.LEADING, button
0265:                        .getHorizontalAlignment());
0266:                assertEquals(SwingConstants.TRAILING, button
0267:                        .getHorizontalTextPosition());
0268:                assertEquals(SwingConstants.CENTER, button
0269:                        .getVerticalAlignment());
0270:                assertEquals(SwingConstants.CENTER, button
0271:                        .getVerticalTextPosition());
0272:            }
0273:
0274:            /*
0275:             * Test method for 'javax.swing.JMenu.getAccessibleContext()'
0276:             */
0277:            @Override
0278:            public void testGetAccessibleContext() {
0279:                boolean assertedValue = (menuItem.getAccessibleContext() != null && menuItem
0280:                        .getAccessibleContext().getClass().getName().equals(
0281:                                "javax.swing.JMenu$AccessibleJMenu"));
0282:                assertTrue("AccessibleContext created properly ", assertedValue);
0283:            }
0284:
0285:            /*
0286:             * Test method for 'javax.swing.JMenu.applyComponentOrientation(ComponentOrientation)'
0287:             */
0288:            public void testApplyComponentOrientation() {
0289:                JMenuItem item = new JMenuItem();
0290:                menu
0291:                        .applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0292:                assertTrue(menu.getPopupMenu().getComponentOrientation()
0293:                        .isLeftToRight());
0294:                menu
0295:                        .applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0296:                assertFalse(menu.getPopupMenu().getComponentOrientation()
0297:                        .isLeftToRight());
0298:                menu.add(item);
0299:                menu
0300:                        .applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0301:                assertFalse(item.getComponentOrientation().isLeftToRight());
0302:            }
0303:
0304:            /*
0305:             * Test method for 'javax.swing.JMenu.setComponentOrientation(ComponentOrientation)'
0306:             */
0307:            public void testSetComponentOrientation() {
0308:                JMenuItem item = new JMenuItem();
0309:                menu
0310:                        .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0311:                assertTrue(menu.getPopupMenu().getComponentOrientation()
0312:                        .isLeftToRight());
0313:                menu
0314:                        .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0315:                assertFalse(menu.getPopupMenu().getComponentOrientation()
0316:                        .isLeftToRight());
0317:                menu.add(item);
0318:                menu
0319:                        .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0320:                assertTrue(item.getComponentOrientation().isLeftToRight());
0321:            }
0322:
0323:            /*
0324:             * Test method for 'javax.swing.JMenu.remove(int)'
0325:             */
0326:            public void testRemoveInt() {
0327:                JMenuItem item1 = new JMenuItem();
0328:                JMenuItem item2 = new JMenuItem();
0329:                menu.add(item1);
0330:                menu.add(item2);
0331:                assertEquals(2, menu.getMenuComponentCount());
0332:                assertSame(item1, menu.getMenuComponent(0));
0333:                assertSame(item2, menu.getMenuComponent(1));
0334:                try {
0335:                    menu.remove(5);
0336:                    fail("no exception has been thrown");
0337:                } catch (IllegalArgumentException e) {
0338:                }
0339:                try {
0340:                    menu.remove(-5);
0341:                    fail("no exception has been thrown");
0342:                } catch (IllegalArgumentException e) {
0343:                }
0344:                menu.remove(0);
0345:                assertEquals(1, menu.getMenuComponentCount());
0346:                assertSame(item2, menu.getMenuComponent(0));
0347:            }
0348:
0349:            /*
0350:             * Test method for 'javax.swing.JMenu.remove(Component)'
0351:             */
0352:            public void testRemoveComponent() {
0353:                JMenuItem item1 = new JMenuItem();
0354:                JMenuItem item2 = new JMenuItem();
0355:                menu.add(item1);
0356:                menu.add(item2);
0357:                assertEquals(2, menu.getMenuComponentCount());
0358:                assertSame(item1, menu.getMenuComponent(0));
0359:                assertSame(item2, menu.getMenuComponent(1));
0360:                menu.remove(new JButton());
0361:                assertEquals(2, menu.getMenuComponentCount());
0362:                menu.remove((Component) item1);
0363:                assertEquals(1, menu.getMenuComponentCount());
0364:                assertSame(item2, menu.getMenuComponent(0));
0365:            }
0366:
0367:            /*
0368:             * Test method for 'javax.swing.JMenu.remove(JMenuItem)'
0369:             */
0370:            public void testRemoveJMenuItem() {
0371:                JMenuItem item1 = new JMenuItem();
0372:                JMenuItem item2 = new JMenuItem();
0373:                menu.add(item1);
0374:                menu.add(item2);
0375:                assertEquals(2, menu.getMenuComponentCount());
0376:                assertSame(item1, menu.getMenuComponent(0));
0377:                assertSame(item2, menu.getMenuComponent(1));
0378:                menu.remove(item1);
0379:                assertEquals(1, menu.getMenuComponentCount());
0380:                assertSame(item2, menu.getMenuComponent(0));
0381:                menu.remove(item1);
0382:                assertEquals(1, menu.getMenuComponentCount());
0383:                assertSame(item2, menu.getMenuComponent(0));
0384:            }
0385:
0386:            /*
0387:             * Test method for 'javax.swing.JMenu.removeAll()'
0388:             */
0389:            public void testRemoveAll() {
0390:                JMenuItem item1 = new JMenuItem();
0391:                JMenuItem item2 = new JMenuItem();
0392:                assertEquals(0, menu.getMenuComponentCount());
0393:                menu.removeAll();
0394:                assertEquals(0, menu.getMenuComponentCount());
0395:                menu.add(item1);
0396:                menu.add(item2);
0397:                assertEquals(2, menu.getMenuComponentCount());
0398:                menu.removeAll();
0399:                assertEquals(0, menu.getMenuComponentCount());
0400:            }
0401:
0402:            /*
0403:             * Test method for 'javax.swing.JMenu.getUIClassID()'
0404:             */
0405:            @Override
0406:            public void testGetUIClassID() {
0407:                assertEquals("MenuUI", menu.getUIClassID());
0408:            }
0409:
0410:            /*
0411:             * Test method for 'javax.swing.JMenu.doClick(int)'
0412:             */
0413:            @Override
0414:            public void testDoClick() {
0415:            }
0416:
0417:            /*
0418:             * Test method for 'javax.swing.JMenu.doClick(int)'
0419:             */
0420:            public void testDoClickInt() {
0421:                JFrame frame = new JFrame();
0422:                JMenuBar menuBar = new JMenuBar();
0423:                frame.getContentPane().add(menuBar);
0424:                JMenu menu1 = new JMenu();
0425:                JMenu menu2 = new JMenu();
0426:                menuBar.add(menu2);
0427:                menu2.add(menu1);
0428:                menu1.add(menu);
0429:                assertFalse(menu.isSelected());
0430:                menu.doClick(0);
0431:                assertTrue(menu.isSelected());
0432:                assertTrue(menu1.isSelected());
0433:                assertTrue(menu2.isSelected());
0434:                frame.dispose();
0435:            }
0436:
0437:            /*
0438:             * Test method for 'javax.swing.JMenu.setSelected(boolean)'
0439:             */
0440:            public void testSetIsSelected() {
0441:                ConcreteMenuListener listener = new ConcreteMenuListener();
0442:                menu.addMenuListener(listener);
0443:                menu.setSelected(true);
0444:                assertTrue(menu.getModel().isSelected());
0445:                assertTrue(menu.isSelected());
0446:                assertEquals("selected", listener.event);
0447:                listener.event = null;
0448:                menu.setSelected(false);
0449:                assertFalse(menu.getModel().isSelected());
0450:                assertFalse(menu.isSelected());
0451:                assertEquals("deselected", listener.event);
0452:                listener.event = null;
0453:            }
0454:
0455:            /*
0456:             * Test method for 'javax.swing.JMenu.setAccelerator(KeyStroke)'
0457:             */
0458:            @Override
0459:            public void testSetAccelerator() {
0460:                try {
0461:                    menu.setAccelerator(null);
0462:                    fail("no exception has been thrown");
0463:                } catch (Error e) {
0464:                }
0465:            }
0466:
0467:            /*
0468:             * Test method for 'javax.swing.JMenu.getComponent()'
0469:             */
0470:            @Override
0471:            public void testGetComponent() {
0472:                assertSame(menu, menu.getComponent());
0473:            }
0474:
0475:            /*
0476:             * Test method for 'javax.swing.JMenu.getSubElements()'
0477:             */
0478:            @Override
0479:            public void testGetSubElements() {
0480:                JMenuItem item1 = new JMenuItem();
0481:                JMenuItem item2 = new JMenuItem();
0482:                JMenuItem item3 = new JMenuItem();
0483:                JMenuItem item4 = new JMenuItem();
0484:                if (!isHarmony()) {
0485:                    assertEquals(0, menu.getSubElements().length);
0486:                } else {
0487:                    assertEquals(1, menu.getSubElements().length);
0488:                    assertTrue(menu.getSubElements()[0] instanceof  JPopupMenu);
0489:                }
0490:                menu.add(item1);
0491:                assertEquals(1, menu.getSubElements().length);
0492:                assertTrue(menu.getSubElements()[0] instanceof  JPopupMenu);
0493:                menu.add(item2);
0494:                assertEquals(1, menu.getSubElements().length);
0495:                assertTrue(menu.getSubElements()[0] instanceof  JPopupMenu);
0496:                menu.addSeparator();
0497:                assertEquals(1, menu.getSubElements().length);
0498:                assertTrue(menu.getSubElements()[0] instanceof  JPopupMenu);
0499:                JButton button = new JButton();
0500:                menu.add(button, 0);
0501:                assertEquals(1, menu.getSubElements().length);
0502:                assertTrue(menu.getSubElements()[0] instanceof  JPopupMenu);
0503:                JMenu subMenu = new JMenu();
0504:                subMenu.add(item3);
0505:                subMenu.add(item4);
0506:                menu.add(subMenu);
0507:                assertEquals(1, menu.getSubElements().length);
0508:                assertTrue(menu.getSubElements()[0] instanceof  JPopupMenu);
0509:            }
0510:
0511:            /*
0512:             * Test method for 'javax.swing.JMenu.menuSelectionChanged(boolean)'
0513:             */
0514:            @Override
0515:            public void testMenuSelectionChanged() {
0516:                ConcreteMenuListener listener = new ConcreteMenuListener();
0517:                menu.addMenuListener(listener);
0518:                menu.menuSelectionChanged(true);
0519:                assertEquals("selected", listener.event);
0520:                assertTrue(menu.getModel().isSelected());
0521:                assertTrue(menu.isSelected());
0522:                listener.event = null;
0523:                menu.menuSelectionChanged(false);
0524:                assertEquals("deselected", listener.event);
0525:                assertFalse(menu.getModel().isSelected());
0526:                assertFalse(menu.isSelected());
0527:                listener.event = null;
0528:            }
0529:
0530:            /*
0531:             * Test method for 'javax.swing.JMenu.add(Action)'
0532:             */
0533:            public void testAddAction() {
0534:                Icon icon = createNewIcon();
0535:                String text = "texttext";
0536:                Action action = new JPopupMenuTest.MyAction(text, icon);
0537:                JMenuItem menuItem = menu.add(action);
0538:                assertEquals(1, menu.getItemCount());
0539:                assertSame(menuItem, menu.getItem(0));
0540:                assertEquals("icon ", icon, menuItem.getIcon());
0541:                assertEquals("text ", text, menuItem.getText());
0542:                assertSame(action, menuItem.getAction());
0543:            }
0544:
0545:            /*
0546:             * Test method for 'javax.swing.JMenu.add(String)'
0547:             */
0548:            public void testAddString() {
0549:                String text1 = "text";
0550:                String text2 = "texttext";
0551:                JMenuItem item1 = menu.add(text1);
0552:                assertEquals(text1, item1.getText());
0553:                assertNull(item1.getIcon());
0554:                assertEquals(1, menu.getItemCount());
0555:                assertSame(item1, menu.getItem(0));
0556:                JMenuItem item2 = menu.add(text2);
0557:                assertEquals(text2, item2.getText());
0558:                assertNull(item2.getIcon());
0559:                assertEquals(2, menu.getItemCount());
0560:                assertSame(item1, menu.getItem(0));
0561:                assertSame(item2, menu.getItem(1));
0562:                assertNotSame(item1, item2);
0563:            }
0564:
0565:            /*
0566:             * Test method for 'javax.swing.JMenu.add(JMenuItem)'
0567:             */
0568:            public void testAddJMenuItem() {
0569:                JMenuItem item1 = new JMenuItem();
0570:                JMenuItem item2 = new JMenuItem();
0571:                JPopupMenu popup = menu.getPopupMenu();
0572:                JMenuItem item = menu.add(item1);
0573:                assertEquals(0, menu.getComponentCount());
0574:                assertEquals(1, menu.getItemCount());
0575:                assertEquals(1, popup.getComponentCount());
0576:                assertSame(item1, popup.getComponent(0));
0577:                assertSame(item, item1);
0578:                item = menu.add(item2);
0579:                assertEquals(0, menu.getComponentCount());
0580:                assertEquals(2, menu.getItemCount());
0581:                assertEquals(2, popup.getComponentCount());
0582:                assertSame(item1, popup.getComponent(0));
0583:                assertSame(item2, popup.getComponent(1));
0584:                assertSame(item, item2);
0585:            }
0586:
0587:            /*
0588:             * Test method for 'javax.swing.JMenu.add(Component)'
0589:             */
0590:            public void testAddComponent() {
0591:                Component item1 = new JMenuItem();
0592:                Component item2 = new JMenuItem();
0593:                Component item3 = new JButton();
0594:                JPopupMenu popup = menu.getPopupMenu();
0595:                Component item = menu.add(item1);
0596:                assertEquals(0, menu.getComponentCount());
0597:                assertEquals(1, menu.getItemCount());
0598:                assertEquals(1, popup.getComponentCount());
0599:                assertSame(item1, popup.getComponent(0));
0600:                assertSame(item, item1);
0601:                item = menu.add(item2);
0602:                assertEquals(0, menu.getComponentCount());
0603:                assertEquals(2, menu.getItemCount());
0604:                assertEquals(2, popup.getComponentCount());
0605:                assertSame(item1, popup.getComponent(0));
0606:                assertSame(item2, popup.getComponent(1));
0607:                assertSame(item, item2);
0608:                item = menu.add(item3);
0609:                assertEquals(0, menu.getComponentCount());
0610:                assertEquals(3, menu.getItemCount());
0611:                assertEquals(3, popup.getComponentCount());
0612:                assertSame(item1, popup.getComponent(0));
0613:                assertSame(item2, popup.getComponent(1));
0614:                assertSame(item3, popup.getComponent(2));
0615:                assertSame(item, item3);
0616:            }
0617:
0618:            /*
0619:             * Test method for 'javax.swing.JMenu.add(Component, int)'
0620:             */
0621:            public void testAddComponentInt() {
0622:                Component item1 = new JMenuItem();
0623:                Component item2 = new JMenuItem();
0624:                Component item3 = new JButton();
0625:                JPopupMenu popup = menu.getPopupMenu();
0626:                Component item = menu.add(item1, 0);
0627:                assertEquals(0, menu.getComponentCount());
0628:                assertEquals(1, menu.getItemCount());
0629:                assertEquals(1, popup.getComponentCount());
0630:                assertSame(item1, popup.getComponent(0));
0631:                assertSame(item, item1);
0632:                item = menu.add(item2, 1);
0633:                assertEquals(0, menu.getComponentCount());
0634:                assertEquals(2, menu.getItemCount());
0635:                assertEquals(2, popup.getComponentCount());
0636:                assertSame(item1, popup.getComponent(0));
0637:                assertSame(item2, popup.getComponent(1));
0638:                assertSame(item, item2);
0639:                item = menu.add(item3, -1);
0640:                assertEquals(0, menu.getComponentCount());
0641:                assertEquals(3, menu.getItemCount());
0642:                assertEquals(3, popup.getComponentCount());
0643:                assertSame(item1, popup.getComponent(0));
0644:                assertSame(item2, popup.getComponent(1));
0645:                assertSame(item3, popup.getComponent(2));
0646:                assertSame(item, item3);
0647:            }
0648:
0649:            /*
0650:             * Test method for 'javax.swing.JMenu.addSeparator()'
0651:             */
0652:            public void testAddSeparator() {
0653:                JMenuItem item1 = new JMenuItem();
0654:                JMenuItem item2 = new JMenuItem();
0655:                JPopupMenu popup = menu.getPopupMenu();
0656:                menu.add(item1);
0657:                assertEquals(1, menu.getItemCount());
0658:                assertSame(item1, menu.getItem(0));
0659:                menu.addSeparator();
0660:                assertEquals(2, menu.getItemCount());
0661:                assertTrue(popup.getComponent(1) instanceof  JPopupMenu.Separator);
0662:                menu.add(item2);
0663:                assertEquals(3, menu.getItemCount());
0664:                assertSame(item1, menu.getItem(0));
0665:                assertNull(menu.getItem(1));
0666:                assertSame(item2, menu.getItem(2));
0667:                menu.addSeparator();
0668:                assertEquals(4, menu.getItemCount());
0669:                assertNull(menu.getItem(3));
0670:                assertTrue(popup.getComponent(3) instanceof  JPopupMenu.Separator);
0671:                assertNotSame(popup.getComponent(1), popup.getComponent(3));
0672:            }
0673:
0674:            /*
0675:             * Test method for 'javax.swing.JMenu.addMenuListener(MenuListener)'
0676:             */
0677:            public void testAddGetRemoveMenuListener() {
0678:                MenuListener listener1 = new ConcreteMenuListener();
0679:                MenuListener listener2 = new ConcreteMenuListener();
0680:                MenuListener listener3 = new ConcreteMenuListener();
0681:                EventListener[] listenersArray = null;
0682:                listenersArray = menu.getMenuListeners();
0683:                int initialValue = listenersArray.length;
0684:                menu.addMenuListener(listener1);
0685:                menu.addMenuListener(listener2);
0686:                menu.addMenuListener(listener2);
0687:                listenersArray = menu.getMenuListeners();
0688:                assertEquals(initialValue + 3, listenersArray.length);
0689:                menu.removeMenuListener(listener1);
0690:                menu.addMenuListener(listener3);
0691:                menu.addMenuListener(listener3);
0692:                listenersArray = menu.getMenuListeners();
0693:                assertEquals(initialValue + 4, listenersArray.length);
0694:                menu.removeMenuListener(listener3);
0695:                menu.removeMenuListener(listener3);
0696:                listenersArray = menu.getMenuListeners();
0697:                assertEquals(initialValue + 2, listenersArray.length);
0698:                menu.removeMenuListener(listener2);
0699:                menu.removeMenuListener(listener2);
0700:                listenersArray = menu.getMenuListeners();
0701:                assertEquals(initialValue, listenersArray.length);
0702:            }
0703:
0704:            /*
0705:             * Test method for 'javax.swing.JMenu.createActionChangeListener(JMenuItem)'
0706:             */
0707:            public void testCreateActionChangeListener() {
0708:                String text1 = "text";
0709:                String text2 = "texttext";
0710:                String text3 = "texttexttext";
0711:                JMenuItem item1 = new JMenuItem(text2);
0712:                AbstractAction action1 = new AbstractAction() {
0713:                    public void actionPerformed(ActionEvent e) {
0714:                    }
0715:                };
0716:                AbstractAction action2 = new AbstractAction() {
0717:                    public void actionPerformed(ActionEvent e) {
0718:                    }
0719:                };
0720:                JMenuItem item2 = new JMenuItem(action2);
0721:                menu.setAction(action1);
0722:                PropertyChangeListener l1 = menu
0723:                        .createActionChangeListener(item1);
0724:                PropertyChangeListener l2 = menu
0725:                        .createActionChangeListener(item2);
0726:                assertNotNull(l1);
0727:                assertNotNull(l2);
0728:                assertNotSame(l1, l2);
0729:                action1.putValue(Action.NAME, text1);
0730:                assertEquals(text1, menu.getText());
0731:                assertEquals(text2, item1.getText());
0732:                action1.addPropertyChangeListener(l1);
0733:                action1.putValue(Action.NAME, text3);
0734:                assertEquals(text3, item1.getText());
0735:                action2.putValue(Action.NAME, text2);
0736:                assertEquals(text2, item2.getText());
0737:            }
0738:
0739:            /*
0740:             * Test method for 'javax.swing.JMenu.createActionComponent(Action)'
0741:             */
0742:            public void testCreateActionComponent() {
0743:                final String command = "dnammoc";
0744:                class MyAction extends AbstractAction {
0745:                    public MyAction(final String text, final Icon icon) {
0746:                        super (text, icon);
0747:                        putValue(Action.ACTION_COMMAND_KEY, command);
0748:                    }
0749:
0750:                    public void actionPerformed(final ActionEvent e) {
0751:                    }
0752:                }
0753:                ;
0754:                Icon icon = createNewIcon();
0755:                String text = "texttext";
0756:                MyAction action = new MyAction(text, icon);
0757:                JMenuItem menuItem1 = menu.createActionComponent(action);
0758:                assertEquals("icon ", icon, menuItem1.getIcon());
0759:                assertEquals("text ", text, menuItem1.getText());
0760:                assertNull("action", menuItem1.getAction());
0761:                assertEquals("command ", text, menuItem1.getActionCommand());
0762:                assertFalse("selected ", menuItem1.isSelected());
0763:                assertTrue("enabled ", menuItem1.isEnabled());
0764:                assertNull("accelerator ", menuItem1.getAccelerator());
0765:                JMenuItem menuItem2 = menu.createActionComponent(action);
0766:                assertNotSame(menuItem1, menuItem2);
0767:                assertEquals("icon ", icon, menuItem2.getIcon());
0768:                assertEquals("text ", text, menuItem2.getText());
0769:                assertNull("action", menuItem1.getAction());
0770:                assertEquals("command ", text, menuItem2.getActionCommand());
0771:                assertFalse("selected ", menuItem2.isSelected());
0772:                assertTrue("enabled ", menuItem2.isEnabled());
0773:                assertNull("accelerator ", menuItem2.getAccelerator());
0774:            }
0775:
0776:            /*
0777:             * Test method for 'javax.swing.JMenu.createWinListener(JPopupMenu)'
0778:             */
0779:            public void testCreateWinListener() {
0780:                JPopupMenu pupop = new JPopupMenu();
0781:                JMenu.WinListener listener1 = menu.createWinListener(pupop);
0782:                JMenu.WinListener listener2 = menu.createWinListener(pupop);
0783:                assertNotNull(listener1);
0784:                assertNotNull(listener2);
0785:                assertNotSame(listener1, listener2);
0786:            }
0787:
0788:            /*
0789:             * Test method for 'javax.swing.JMenu.fireMenuCanceled()'
0790:             */
0791:            public void testFireMenuCanceled() {
0792:                ConcreteMenuListener listener1 = new ConcreteMenuListener();
0793:                ConcreteMenuListener listener2 = new ConcreteMenuListener();
0794:                menu.addMenuListener(listener1);
0795:                menu.addMenuListener(listener2);
0796:                menu.fireMenuCanceled();
0797:                assertEquals("event fired properly ", "canceled",
0798:                        listener1.event);
0799:                assertEquals("event fired properly ", "canceled",
0800:                        listener2.event);
0801:                assertEquals("source ", menu, listener1.src);
0802:                assertEquals("source ", menu, listener2.src);
0803:            }
0804:
0805:            /*
0806:             * Test method for 'javax.swing.JMenu.fireMenuDeselected()'
0807:             */
0808:            public void testFireMenuDeselected() {
0809:                ConcreteMenuListener listener1 = new ConcreteMenuListener();
0810:                ConcreteMenuListener listener2 = new ConcreteMenuListener();
0811:                menu.addMenuListener(listener1);
0812:                menu.addMenuListener(listener2);
0813:                menu.fireMenuDeselected();
0814:                assertEquals("event fired properly ", "deselected",
0815:                        listener1.event);
0816:                assertEquals("event fired properly ", "deselected",
0817:                        listener2.event);
0818:                assertEquals("source ", menu, listener1.src);
0819:                assertEquals("source ", menu, listener2.src);
0820:            }
0821:
0822:            /*
0823:             * Test method for 'javax.swing.JMenu.fireMenuSelected()'
0824:             */
0825:            public void testFireMenuSelected() {
0826:                ConcreteMenuListener listener1 = new ConcreteMenuListener();
0827:                ConcreteMenuListener listener2 = new ConcreteMenuListener();
0828:                menu.addMenuListener(listener1);
0829:                menu.addMenuListener(listener2);
0830:                menu.fireMenuSelected();
0831:                assertEquals("event fired properly ", "selected",
0832:                        listener1.event);
0833:                assertEquals("event fired properly ", "selected",
0834:                        listener2.event);
0835:                assertEquals("source ", menu, listener1.src);
0836:                assertEquals("source ", menu, listener2.src);
0837:            }
0838:
0839:            /*
0840:             * Test method for 'javax.swing.JMenu.getMenuComponentCount()'
0841:             */
0842:            public void testGetMenuComponentCount() {
0843:                JMenuItem item1 = new JMenuItem();
0844:                JMenuItem item2 = new JMenuItem();
0845:                assertEquals(0, menu.getMenuComponentCount());
0846:                menu.add(item1);
0847:                assertEquals(1, menu.getMenuComponentCount());
0848:                menu.add(item2);
0849:                assertEquals(2, menu.getMenuComponentCount());
0850:                menu.addSeparator();
0851:                assertEquals(3, menu.getMenuComponentCount());
0852:                menu.add(new JButton(), 0);
0853:                assertEquals(4, menu.getMenuComponentCount());
0854:            }
0855:
0856:            /*
0857:             * Test method for 'javax.swing.JMenu.getItemCount()'
0858:             */
0859:            public void testGetItemCount() {
0860:                JMenuItem item1 = new JMenuItem();
0861:                JMenuItem item2 = new JMenuItem();
0862:                assertEquals(0, menu.getItemCount());
0863:                menu.add(item1);
0864:                assertEquals(1, menu.getItemCount());
0865:                menu.add(item2);
0866:                assertEquals(2, menu.getItemCount());
0867:                menu.addSeparator();
0868:                assertEquals(3, menu.getItemCount());
0869:                menu.add(new JButton(), 0);
0870:                assertEquals(4, menu.getItemCount());
0871:            }
0872:
0873:            /*
0874:             * Test method for 'javax.swing.JMenu.getMenuComponent(int)'
0875:             */
0876:            public void testGetMenuComponent() {
0877:                JMenuItem item1 = new JMenuItem();
0878:                JMenuItem item2 = new JMenuItem();
0879:                assertNull(menu.getMenuComponent(0));
0880:                menu.add(item1);
0881:                assertEquals(item1, menu.getMenuComponent(0));
0882:                menu.add(item2);
0883:                assertEquals(item1, menu.getMenuComponent(0));
0884:                assertEquals(item2, menu.getMenuComponent(1));
0885:                menu.addSeparator();
0886:                assertEquals(item1, menu.getMenuComponent(0));
0887:                assertEquals(item2, menu.getMenuComponent(1));
0888:                assertTrue(menu.getMenuComponent(2) instanceof  JSeparator);
0889:                menu.add(new JButton(), 3);
0890:                assertEquals(item1, menu.getMenuComponent(0));
0891:                assertEquals(item2, menu.getMenuComponent(1));
0892:                assertTrue(menu.getMenuComponent(2) instanceof  JSeparator);
0893:                assertTrue(menu.getMenuComponent(3) instanceof  JButton);
0894:            }
0895:
0896:            /*
0897:             * Test method for 'javax.swing.JMenu.getItem(int)'
0898:             */
0899:            public void testGetItem() {
0900:                JMenuItem item1 = new JMenuItem();
0901:                JMenuItem item2 = new JMenuItem();
0902:                assertNull(menu.getItem(0));
0903:                menu.add(item1);
0904:                assertEquals(item1, menu.getItem(0));
0905:                menu.add(item2);
0906:                assertEquals(item1, menu.getItem(0));
0907:                assertEquals(item2, menu.getItem(1));
0908:                menu.addSeparator();
0909:                assertEquals(item1, menu.getItem(0));
0910:                assertEquals(item2, menu.getItem(1));
0911:                assertNull(menu.getItem(2));
0912:                menu.add(new JButton(), 3);
0913:                assertEquals(item1, menu.getMenuComponent(0));
0914:                assertEquals(item2, menu.getMenuComponent(1));
0915:                assertNull(menu.getItem(2));
0916:                assertNull(menu.getItem(3));
0917:            }
0918:
0919:            /*
0920:             * Test method for 'javax.swing.JMenu.getMenuComponents()'
0921:             */
0922:            public void testGetMenuComponents() {
0923:                JMenuItem item1 = new JMenuItem();
0924:                JMenuItem item2 = new JMenuItem();
0925:                JMenuItem item3 = new JMenuItem();
0926:                JMenuItem item4 = new JMenuItem();
0927:                assertEquals(0, menu.getMenuComponents().length);
0928:                menu.add(item1);
0929:                assertEquals(1, menu.getMenuComponents().length);
0930:                assertSame(item1, menu.getMenuComponents()[0]);
0931:                menu.add(item2);
0932:                assertEquals(2, menu.getMenuComponents().length);
0933:                assertSame(item1, menu.getMenuComponents()[0]);
0934:                assertSame(item2, menu.getMenuComponents()[1]);
0935:                menu.addSeparator();
0936:                assertEquals(3, menu.getMenuComponents().length);
0937:                assertSame(item1, menu.getMenuComponents()[0]);
0938:                assertSame(item2, menu.getMenuComponents()[1]);
0939:                assertTrue(menu.getMenuComponents()[2] instanceof  JSeparator);
0940:                JButton button = new JButton();
0941:                menu.add(button, 0);
0942:                assertEquals(4, menu.getMenuComponents().length);
0943:                assertTrue(menu.getMenuComponents()[0] instanceof  JButton);
0944:                assertSame(item1, menu.getMenuComponents()[1]);
0945:                assertSame(item2, menu.getMenuComponents()[2]);
0946:                assertTrue(menu.getMenuComponents()[3] instanceof  JSeparator);
0947:                JMenu subMenu = new JMenu();
0948:                subMenu.add(item3);
0949:                subMenu.add(item4);
0950:                menu.add(subMenu);
0951:                assertEquals(5, menu.getMenuComponents().length);
0952:                assertTrue(menu.getMenuComponents()[4] instanceof  JMenu);
0953:            }
0954:
0955:            /*
0956:             * Test method for 'javax.swing.JMenu.getPopupMenu()'
0957:             */
0958:            public void testGetPopupMenu() {
0959:                assertNotNull(menu.getPopupMenu());
0960:                assertNull(menu.getPopupMenu().getLabel());
0961:                assertEquals(0, menu.getPopupMenu().getComponentCount());
0962:                JMenuItem item = menu.add("item");
0963:                assertEquals(1, menu.getPopupMenu().getComponentCount());
0964:                assertSame(item, menu.getPopupMenu().getComponent(0));
0965:            }
0966:
0967:            /*
0968:             * Test method for 'javax.swing.JMenu.getPopupMenuOrigin()'
0969:             */
0970:            public void testGetPopupMenuOrigin() {
0971:                int offsetX1 = 50;
0972:                int offsetY1 = 60;
0973:                int offsetX2 = 20;
0974:                int offsetY2 = 30;
0975:                JMenuBar menuBar = new JMenuBar();
0976:                JMenu menu2 = new JMenu();
0977:                JWindow frame = new JWindow();
0978:                menuBar.add(menu);
0979:                frame.setLocation(500, 500);
0980:                frame.getContentPane().add(menuBar);
0981:                menu.setPreferredSize(new Dimension(200, 200));
0982:                menu2.setPreferredSize(new Dimension(100, 100));
0983:                frame.pack();
0984:                menu.getPopupMenu().setPreferredSize(new Dimension(50, 50));
0985:                UIManager.put("Menu.menuPopupOffsetX", new Integer(offsetX1));
0986:                UIManager.put("Menu.menuPopupOffsetY", new Integer(offsetY1));
0987:                UIManager
0988:                        .put("Menu.submenuPopupOffsetX", new Integer(offsetX2));
0989:                UIManager
0990:                        .put("Menu.submenuPopupOffsetY", new Integer(offsetY2));
0991:                frame.setVisible(true);
0992:                assertEquals(new Point(offsetX1, menu.getHeight() + offsetY1),
0993:                        menu.getPopupMenuOrigin());
0994:                frame
0995:                        .applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
0996:                assertEquals(new Point(menu.getWidth()
0997:                        - menu.getPopupMenu().getPreferredSize().width
0998:                        - offsetX1, menu.getHeight() + offsetY1), menu
0999:                        .getPopupMenuOrigin());
1000:                menuBar.remove(menu);
1001:                menuBar.add(menu2);
1002:                menu2.add(menu);
1003:                frame.pack();
1004:                frame
1005:                        .applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
1006:                menu2.setPopupMenuVisible(true);
1007:                assertEquals(new Point(menu.getWidth() + offsetX2, offsetY2),
1008:                        menu.getPopupMenuOrigin());
1009:                frame
1010:                        .applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
1011:                assertEquals(new Point(-offsetX2
1012:                        - menu.getPopupMenu().getPreferredSize().width,
1013:                        offsetY2), menu.getPopupMenuOrigin());
1014:                frame.dispose();
1015:            }
1016:
1017:            /*
1018:             * Test method for 'javax.swing.JMenu.insert(String, int)'
1019:             */
1020:            public void testInsertStringInt() {
1021:                String text1 = "text";
1022:                String text2 = "texttext";
1023:                menu.insert(text1, 0);
1024:                JMenuItem item1 = menu.getItem(0);
1025:                assertEquals(text1, item1.getText());
1026:                assertNull(item1.getIcon());
1027:                assertEquals(1, menu.getItemCount());
1028:                assertEquals(item1, menu.getItem(0));
1029:                menu.insert(text2, 0);
1030:                JMenuItem item2 = menu.getItem(0);
1031:                assertEquals(text2, item2.getText());
1032:                assertNull(item2.getIcon());
1033:                assertEquals(2, menu.getItemCount());
1034:                assertEquals(item2, menu.getItem(0));
1035:                assertEquals(item1, menu.getItem(1));
1036:                assertNotSame(item1, item2);
1037:                try {
1038:                    menu.insert(text1, -6);
1039:                    fail("no exception has been thrown");
1040:                } catch (IllegalArgumentException e) {
1041:                }
1042:                menu.insert(text1, 5);
1043:                assertEquals(3, menu.getItemCount());
1044:                item1 = menu.getItem(2);
1045:                assertEquals(text1, item1.getText());
1046:                assertNull(item1.getIcon());
1047:            }
1048:
1049:            /*
1050:             * Test method for 'javax.swing.JMenu.insert(JMenuItem, int)'
1051:             */
1052:            public void testInsertJMenuItemInt() {
1053:                JMenuItem item1 = new JMenuItem();
1054:                JMenuItem item2 = new JMenuItem();
1055:                assertSame(item1, menu.insert(item1, 0));
1056:                assertEquals(1, menu.getItemCount());
1057:                assertEquals(item1, menu.getItem(0));
1058:                assertSame(item2, menu.insert(item2, 0));
1059:                assertEquals(2, menu.getItemCount());
1060:                assertEquals(item2, menu.getItem(0));
1061:                assertEquals(item1, menu.getItem(1));
1062:                assertNotSame(item1, item2);
1063:                try {
1064:                    menu.insert(item1, -6);
1065:                    fail("no exception has been thrown");
1066:                } catch (IllegalArgumentException e) {
1067:                }
1068:                menu.insert(item1, 5);
1069:                assertEquals(2, menu.getItemCount());
1070:            }
1071:
1072:            /*
1073:             * Test method for 'javax.swing.JMenu.insert(Action, int)'
1074:             */
1075:            public void testInsertActionInt() {
1076:                Icon icon = createNewIcon();
1077:                String text = "texttext";
1078:                MyAction action1 = new MyAction(text, icon);
1079:                MyAction action2 = new MyAction(text, icon);
1080:                JMenuItem item = menu.insert(action1, 0);
1081:                assertEquals(1, menu.getItemCount());
1082:                JMenuItem menuItem = menu.getItem(0);
1083:                assertSame(item, menuItem);
1084:                assertEquals("icon ", icon, menuItem.getIcon());
1085:                assertEquals("text ", text, menuItem.getText());
1086:                item = menu.insert(action2, 1);
1087:                assertEquals(2, menu.getItemCount());
1088:                menuItem = menu.getItem(1);
1089:                assertSame(item, menuItem);
1090:                assertEquals("icon ", icon, menuItem.getIcon());
1091:                assertEquals("text ", text, menuItem.getText());
1092:                menu.insert(action1, 16);
1093:                assertEquals(3, menu.getItemCount());
1094:                menuItem = menu.getItem(2);
1095:                assertEquals("icon ", icon, menuItem.getIcon());
1096:                assertEquals("text ", text, menuItem.getText());
1097:                try {
1098:                    menu.insert(action1, -3);
1099:                    fail("no exception has been thrown");
1100:                } catch (IllegalArgumentException e) {
1101:                }
1102:            }
1103:
1104:            /*
1105:             * Test method for 'javax.swing.JMenu.insertSeparator(int)'
1106:             */
1107:            public void testInsertSeparator() {
1108:                menu.insertSeparator(0);
1109:                assertEquals(1, menu.getItemCount());
1110:                assertNull(menu.getItem(0));
1111:                assertTrue(menu.getPopupMenu().getComponent(0) instanceof  JSeparator);
1112:                menu.insertSeparator(0);
1113:                assertEquals(2, menu.getItemCount());
1114:                assertNull(menu.getItem(0));
1115:                assertNull(menu.getItem(1));
1116:                assertTrue(menu.getPopupMenu().getComponent(0) instanceof  JSeparator);
1117:                assertTrue(menu.getPopupMenu().getComponent(1) instanceof  JSeparator);
1118:                try {
1119:                    menu.insertSeparator(-6);
1120:                    fail("no exception has been thrown");
1121:                } catch (IllegalArgumentException e) {
1122:                }
1123:                menu.insertSeparator(5);
1124:                assertEquals(3, menu.getItemCount());
1125:            }
1126:
1127:            /*
1128:             * Test method for 'javax.swing.JMenu.isMenuComponent(Component)'
1129:             */
1130:            public void testIsMenuComponent() {
1131:                JMenuItem item1 = new JMenuItem();
1132:                JMenuItem item2 = new JMenuItem();
1133:                JMenuItem item3 = new JMenuItem();
1134:                JMenuItem item4 = new JMenuItem();
1135:                assertFalse(menu.isMenuComponent(item1));
1136:                assertTrue(menu.isMenuComponent(menu));
1137:                menu.add(item1);
1138:                assertTrue(menu.isMenuComponent(item1));
1139:                assertTrue(menu.isMenuComponent(menu));
1140:                assertFalse(menu.isMenuComponent(item2));
1141:                menu.add(item2);
1142:                assertTrue(menu.isMenuComponent(item2));
1143:                assertTrue(menu.isMenuComponent(item1));
1144:                assertTrue(menu.isMenuComponent(menu));
1145:                menu.addSeparator();
1146:                assertTrue(menu.isMenuComponent(item2));
1147:                assertTrue(menu.isMenuComponent(item1));
1148:                assertTrue(menu.isMenuComponent(menu));
1149:                JButton button = new JButton();
1150:                menu.add(button, 0);
1151:                assertTrue(menu.isMenuComponent(button));
1152:                assertTrue(menu.isMenuComponent(item2));
1153:                assertTrue(menu.isMenuComponent(item1));
1154:                assertTrue(menu.isMenuComponent(menu));
1155:                JMenu subMenu = new JMenu();
1156:                subMenu.add(item3);
1157:                subMenu.add(item4);
1158:                menu.add(subMenu);
1159:                assertTrue(menu.isMenuComponent(subMenu));
1160:                assertTrue(menu.isMenuComponent(item3));
1161:                assertTrue(menu.isMenuComponent(item4));
1162:                assertTrue(menu.isMenuComponent(button));
1163:                assertTrue(menu.isMenuComponent(item2));
1164:                assertTrue(menu.isMenuComponent(item1));
1165:                assertTrue(menu.isMenuComponent(menu));
1166:                assertFalse(menu.isMenuComponent(null));
1167:            }
1168:
1169:            /*
1170:             * Test method for 'javax.swing.JMenu.isTearOff()'
1171:             */
1172:            public void testIsTearOff() {
1173:                try {
1174:                    menu.isTearOff();
1175:                    fail("no exception has been thrown");
1176:                } catch (Error e) {
1177:                }
1178:            }
1179:
1180:            /*
1181:             * Test method for 'javax.swing.JMenu.isTopLevelMenu()'
1182:             */
1183:            public void testIsTopLevelMenu() {
1184:                assertFalse(menu.isTopLevelMenu());
1185:                JMenuBar menuBar = new JMenuBar();
1186:                JMenu menu2 = new JMenu();
1187:                menuBar.add(menu);
1188:                menuBar.add(menu2);
1189:                assertTrue(menu.isTopLevelMenu());
1190:                menu2.add(menu);
1191:                assertFalse(menu.isTopLevelMenu());
1192:            }
1193:
1194:            /*
1195:             * Test method for 'javax.swing.JMenu.setDelay(int)'
1196:             */
1197:            public void testGetSetDelay() {
1198:                int delay1 = 1000;
1199:                int delay2 = -1000;
1200:                menu.setDelay(0);
1201:                menu.setDelay(delay1);
1202:                assertEquals("delay", delay1, menu.getDelay());
1203:                try {
1204:                    menu.setDelay(delay2);
1205:                    fail("no exception has been thrown");
1206:                } catch (IllegalArgumentException e) {
1207:                }
1208:            }
1209:
1210:            /*
1211:             * Test method for 'javax.swing.JMenu.setMenuLocation(int, int)'
1212:             */
1213:            public void testSetMenuLocation() {
1214:                int x = 100;
1215:                int y = 200;
1216:                menu.getPopupMenu().setVisible(true);
1217:                menu.setMenuLocation(x, y);
1218:                assertEquals(new Point(x, y), menu.getPopupMenu()
1219:                        .getLocationOnScreen());
1220:                assertEquals(new Point(0, 0), menu.getPopupMenu().getLocation());
1221:            }
1222:
1223:            /*
1224:             * Test method for 'javax.swing.JMenu.setPopupMenuVisible(boolean)'
1225:             */
1226:            public void testSetIsPopupMenuVisible() throws InterruptedException {
1227:                menu.setPopupMenuVisible(true);
1228:                assertFalse(menu.isPopupMenuVisible());
1229:                JWindow frame = new JWindow();
1230:                frame.setLocation(300, 300);
1231:                menu.setPreferredSize(new Dimension(200, 200));
1232:                JMenuBar bar = new JMenuBar();
1233:                bar.add(menu);
1234:                frame.getContentPane().add(bar);
1235:                frame.pack();
1236:                frame.setVisible(true);
1237:                menu.setPopupMenuVisible(true);
1238:                assertTrue(menu.isPopupMenuVisible());
1239:                assertSame(menu, menu.getPopupMenu().getInvoker());
1240:                assertEquals(new Point(), menu.getPopupMenu().getLocation());
1241:                Point menuLocation = menu.getLocationOnScreen();
1242:                menuLocation.translate(0, menu.getHeight());
1243:                assertEquals(menuLocation, menu.getPopupMenu()
1244:                        .getLocationOnScreen());
1245:                menu.setPopupMenuVisible(false);
1246:                assertFalse(menu.isPopupMenuVisible());
1247:                frame.dispose();
1248:            }
1249:
1250:            @Override
1251:            public void testNumberOfModelListeners() {
1252:                button.setUI(null);
1253:                DefaultButtonModel model = (DefaultButtonModel) button
1254:                        .getModel();
1255:                assertEquals("model's action listeners ", 1, model
1256:                        .getActionListeners().length);
1257:                assertEquals("model's item listeners ", 1, model
1258:                        .getItemListeners().length);
1259:                if (isHarmony()) {
1260:                    assertEquals("model's change listeners ", 1, model
1261:                            .getChangeListeners().length);
1262:                } else {
1263:                    assertEquals("model's change listeners ", 2, model
1264:                            .getChangeListeners().length);
1265:                }
1266:            }
1267:
1268:            @Override
1269:            public void testConfigurePropertiesFromAction() {
1270:                Icon icon1 = createNewIcon();
1271:                Icon icon2 = createNewIcon();
1272:                KeyStroke ks1 = KeyStroke.getKeyStroke('a');
1273:                KeyStroke ks2 = KeyStroke.getKeyStroke('b');
1274:                String text1 = "texttext1";
1275:                String text2 = "texttext2";
1276:                String text3 = "texttext3";
1277:                String text4 = "texttext4";
1278:                AbstractAction action1 = new AbstractAction(text1, icon1) {
1279:                    public void actionPerformed(final ActionEvent event) {
1280:                    }
1281:                };
1282:                AbstractAction action2 = new AbstractAction(text2, icon2) {
1283:                    public void actionPerformed(final ActionEvent event) {
1284:                    }
1285:                };
1286:                action1.setEnabled(true);
1287:                action1.putValue(Action.SHORT_DESCRIPTION, text3);
1288:                action1.putValue(Action.MNEMONIC_KEY, new Integer(1));
1289:                button.setAction(action1);
1290:                assertEquals("action ", action1, button.getAction());
1291:                assertTrue("enabled ", button.isEnabled());
1292:                assertTrue("enabled ", action1.isEnabled());
1293:                action1.setEnabled(false);
1294:                button.isEnabled();
1295:                assertFalse("enabled ", button.isEnabled());
1296:                assertFalse("enabled ", action1.isEnabled());
1297:                assertEquals("icon ", icon1, button.getIcon());
1298:                action1.putValue(Action.SMALL_ICON, icon2);
1299:                assertEquals("icon ", icon2, button.getIcon());
1300:                button.setIcon(icon2);
1301:                action1.putValue(Action.SMALL_ICON, null);
1302:                assertNull("icon ", button.getIcon());
1303:                if (isHarmony()) {
1304:                    assertEquals("mnemonic ", 1, button.getMnemonic());
1305:                    action1.putValue(Action.MNEMONIC_KEY, new Integer(27));
1306:                    assertEquals("mnemonic ", 27, button.getMnemonic());
1307:                    action1.putValue(Action.ACCELERATOR_KEY, ks1);
1308:                    assertNull("accelerator ", menuItem.getAccelerator());
1309:                }
1310:                assertEquals("text ", text1, button.getText());
1311:                action1.putValue(Action.NAME, text2);
1312:                assertEquals("text ", text2, button.getText());
1313:                if (isHarmony()) {
1314:                    assertEquals("ToolTipText ", text3, button.getToolTipText());
1315:                    action1.putValue(Action.SHORT_DESCRIPTION, text4);
1316:                    assertEquals("ToolTipText ", text4, button.getToolTipText());
1317:                }
1318:                action2.putValue(Action.ACCELERATOR_KEY, ks2);
1319:                button.setAction(action2);
1320:                action1.putValue(Action.SHORT_DESCRIPTION, text4);
1321:                assertNull("ToolTipText ", button.getToolTipText());
1322:                if (isHarmony()) {
1323:                    action2.putValue(Action.SHORT_DESCRIPTION, text4);
1324:                    assertEquals("ToolTipText ", text4, button.getToolTipText());
1325:                    assertNull("accelerator ", menuItem.getAccelerator());
1326:                }
1327:            }
1328:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.