Source Code Cross Referenced for JMenuItemTest.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 Alexander T. Simbirtsev
019:         * @version $Revision$
020:         */package javax.swing;
021:
022:        import java.awt.event.ActionEvent;
023:        import java.awt.event.KeyEvent;
024:        import java.awt.event.MouseEvent;
025:        import java.util.EventListener;
026:        import javax.accessibility.AccessibleRole;
027:        import javax.swing.event.MenuDragMouseEvent;
028:        import javax.swing.event.MenuDragMouseListener;
029:        import javax.swing.event.MenuKeyEvent;
030:        import javax.swing.event.MenuKeyListener;
031:
032:        @SuppressWarnings("serial")
033:        public class JMenuItemTest extends AbstractButtonTest {
034:            protected JMenuItem menuItem = null;
035:
036:            class ConcreteMenuKeyListener implements  MenuKeyListener {
037:                public Object event;
038:
039:                public void menuKeyPressed(MenuKeyEvent e) {
040:                    event = "pressed";
041:                }
042:
043:                public void menuKeyReleased(MenuKeyEvent e) {
044:                    event = "released";
045:                }
046:
047:                public void menuKeyTyped(MenuKeyEvent e) {
048:                    event = "typed";
049:                }
050:            };
051:
052:            class ConcreteMenuDragMouseListener implements 
053:                    MenuDragMouseListener {
054:                public Object event;
055:
056:                public void menuDragMouseDragged(MenuDragMouseEvent e) {
057:                    event = "dragged";
058:                }
059:
060:                public void menuDragMouseEntered(MenuDragMouseEvent e) {
061:                    event = "entered";
062:                }
063:
064:                public void menuDragMouseExited(MenuDragMouseEvent e) {
065:                    event = "exited";
066:                }
067:
068:                public void menuDragMouseReleased(MenuDragMouseEvent e) {
069:                    event = "released";
070:                }
071:            };
072:
073:            @Override
074:            protected void setUp() throws Exception {
075:                super .setUp();
076:                menuItem = new JMenuItem();
077:                button = menuItem;
078:            }
079:
080:            @Override
081:            protected void tearDown() throws Exception {
082:                menuItem = null;
083:                super .tearDown();
084:            }
085:
086:            /*
087:             * Test method for 'javax.swing.JMenuItem.getAccessibleContext()'
088:             */
089:            public void testGetAccessibleContext() {
090:                boolean assertedValue = (menuItem.getAccessibleContext() != null && menuItem
091:                        .getAccessibleContext().getClass().getName().equals(
092:                                "javax.swing.JMenuItem$AccessibleJMenuItem"));
093:                assertTrue("AccessibleContext created properly ", assertedValue);
094:                assertEquals("AccessibleRole", AccessibleRole.MENU_ITEM,
095:                        menuItem.getAccessibleContext().getAccessibleRole());
096:            }
097:
098:            /*
099:             * Test method for 'javax.swing.JMenuItem.getUIClassID()'
100:             */
101:            public void testGetUIClassID() {
102:                assertEquals("MenuItemUI", menuItem.getUIClassID());
103:            }
104:
105:            /*
106:             * Test method for 'javax.swing.JMenuItem.JMenuItem()'
107:             */
108:            public void testJMenuItem() {
109:                assertTrue("default buttonModel ",
110:                        button.getModel() instanceof  DefaultButtonModel);
111:                assertNull("icon ", button.getIcon());
112:                assertEquals("text ", "", button.getText());
113:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
114:                assertFalse(menuItem.isFocusable());
115:                assertEquals(SwingConstants.LEADING, button
116:                        .getHorizontalAlignment());
117:                assertEquals(SwingConstants.TRAILING, button
118:                        .getHorizontalTextPosition());
119:                assertEquals(SwingConstants.CENTER, button
120:                        .getVerticalAlignment());
121:                assertEquals(SwingConstants.CENTER, button
122:                        .getVerticalTextPosition());
123:            }
124:
125:            /*
126:             * Test method for 'javax.swing.JMenuItem.JMenuItem(Icon)'
127:             */
128:            public void testJMenuItemIcon() {
129:                Icon icon = createNewIcon();
130:                menuItem = new JMenuItem(icon);
131:                assertTrue("default buttonModel ",
132:                        button.getModel() instanceof  DefaultButtonModel);
133:                assertEquals("icon ", icon, menuItem.getIcon());
134:                assertEquals("text ", "", menuItem.getText());
135:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
136:                assertFalse(menuItem.isFocusable());
137:                assertEquals(SwingConstants.LEADING, button
138:                        .getHorizontalAlignment());
139:                assertEquals(SwingConstants.TRAILING, button
140:                        .getHorizontalTextPosition());
141:                assertEquals(SwingConstants.CENTER, button
142:                        .getVerticalAlignment());
143:                assertEquals(SwingConstants.CENTER, button
144:                        .getVerticalTextPosition());
145:            }
146:
147:            /*
148:             * Test method for 'javax.swing.JMenuItem.JMenuItem(String)'
149:             */
150:            public void testJMenuItemString() {
151:                String text = "texttext";
152:                menuItem = new JMenuItem(text);
153:                assertTrue("default buttonModel ",
154:                        button.getModel() instanceof  DefaultButtonModel);
155:                assertNull("icon ", menuItem.getIcon());
156:                assertEquals("text ", text, menuItem.getText());
157:                assertFalse(menuItem.isFocusable());
158:                assertEquals(SwingConstants.LEADING, button
159:                        .getHorizontalAlignment());
160:                assertEquals(SwingConstants.TRAILING, button
161:                        .getHorizontalTextPosition());
162:                assertEquals(SwingConstants.CENTER, button
163:                        .getVerticalAlignment());
164:                assertEquals(SwingConstants.CENTER, button
165:                        .getVerticalTextPosition());
166:            }
167:
168:            /*
169:             * Test method for 'javax.swing.JMenuItem.JMenuItem(Action)'
170:             */
171:            public void testJMenuItemAction() {
172:                final String command = "dnammoc";
173:                final KeyStroke accelerator = KeyStroke.getKeyStroke('a');
174:                class MyAction extends AbstractAction {
175:                    public MyAction(final String text, final Icon icon) {
176:                        super (text, icon);
177:                        putValue(Action.ACTION_COMMAND_KEY, command);
178:                        putValue(Action.ACCELERATOR_KEY, accelerator);
179:                    }
180:
181:                    public void actionPerformed(final ActionEvent e) {
182:                    }
183:                }
184:                ;
185:                Icon icon = createNewIcon();
186:                String text = "texttext";
187:                MyAction action = new MyAction(text, icon);
188:                menuItem = new JMenuItem(action);
189:                assertEquals("icon ", icon, menuItem.getIcon());
190:                assertEquals("text ", text, menuItem.getText());
191:                assertEquals("action", action, menuItem.getAction());
192:                assertEquals("command ", command, menuItem.getActionCommand());
193:                assertFalse("selected ", menuItem.isSelected());
194:                assertTrue("enabled ", menuItem.isEnabled());
195:                assertEquals("accelerator ", accelerator, menuItem
196:                        .getAccelerator());
197:                assertFalse(menuItem.isFocusable());
198:                action.setEnabled(false);
199:                menuItem = new JMenuItem(action);
200:                assertEquals("icon ", icon, menuItem.getIcon());
201:                assertEquals("text ", text, menuItem.getText());
202:                assertEquals("action", action, menuItem.getAction());
203:                assertEquals("command ", command, menuItem.getActionCommand());
204:                assertFalse("selected ", menuItem.isSelected());
205:                assertFalse("enabled ", menuItem.isEnabled());
206:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
207:                menuItem = new JMenuItem((Action) null);
208:                assertNull("icon ", menuItem.getIcon());
209:                assertNull("text ", menuItem.getText());
210:                assertNull("action", menuItem.getAction());
211:                assertNull("command ", menuItem.getActionCommand());
212:                assertFalse("selected ", menuItem.isSelected());
213:                assertTrue("enabled ", menuItem.isEnabled());
214:                assertTrue("menuItem model is of the proper type", menuItem
215:                        .getModel() instanceof  DefaultButtonModel);
216:                assertEquals(SwingConstants.LEADING, button
217:                        .getHorizontalAlignment());
218:                assertEquals(SwingConstants.TRAILING, button
219:                        .getHorizontalTextPosition());
220:                assertEquals(SwingConstants.CENTER, button
221:                        .getVerticalAlignment());
222:                assertEquals(SwingConstants.CENTER, button
223:                        .getVerticalTextPosition());
224:            }
225:
226:            /*
227:             * Test method for 'javax.swing.JMenuItem.JMenuItem(String, Icon)'
228:             */
229:            public void testJMenuItemStringIcon() {
230:                Icon icon = createNewIcon();
231:                String text = "texttext";
232:                menuItem = new JMenuItem(text, icon);
233:                assertTrue("menuItem model is of the proper type", menuItem
234:                        .getModel() instanceof  DefaultButtonModel);
235:                assertEquals("icon ", icon, menuItem.getIcon());
236:                assertEquals("text ", text, menuItem.getText());
237:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
238:                assertFalse(menuItem.isFocusable());
239:                assertEquals(SwingConstants.LEADING, button
240:                        .getHorizontalAlignment());
241:                assertEquals(SwingConstants.TRAILING, button
242:                        .getHorizontalTextPosition());
243:                assertEquals(SwingConstants.CENTER, button
244:                        .getVerticalAlignment());
245:                assertEquals(SwingConstants.CENTER, button
246:                        .getVerticalTextPosition());
247:            }
248:
249:            /*
250:             * Test method for 'javax.swing.JMenuItem.JMenuItem(String, int)'
251:             */
252:            public void testJMenuItemStringInt() {
253:                int mnemonic = 100;
254:                String text = "texttext";
255:                menuItem = new JMenuItem(text, mnemonic);
256:                assertTrue("menuItem model is of the proper type", menuItem
257:                        .getModel() instanceof  DefaultButtonModel);
258:                assertNull("icon ", menuItem.getIcon());
259:                assertEquals("mnemonic ", mnemonic, menuItem.getMnemonic());
260:                assertEquals("text ", text, menuItem.getText());
261:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
262:                assertFalse(menuItem.isFocusable());
263:                assertEquals(SwingConstants.LEADING, button
264:                        .getHorizontalAlignment());
265:                assertEquals(SwingConstants.TRAILING, button
266:                        .getHorizontalTextPosition());
267:                assertEquals(SwingConstants.CENTER, button
268:                        .getVerticalAlignment());
269:                assertEquals(SwingConstants.CENTER, button
270:                        .getVerticalTextPosition());
271:            }
272:
273:            /*
274:             * Test method for 'javax.swing.JMenuItem.setArmed(boolean)'
275:             */
276:            public void testSetArmed() {
277:                PropertyChangeController listener = new PropertyChangeController();
278:                menuItem.setArmed(false);
279:                menuItem.addPropertyChangeListener(listener);
280:                menuItem.setArmed(true);
281:                assertFalse("event's not been fired ", listener.isChanged());
282:                assertTrue("armed", menuItem.isArmed());
283:                assertTrue("armed", menuItem.getModel().isArmed());
284:                listener.reset();
285:                menuItem.setArmed(false);
286:                assertFalse("event's not been fired ", listener.isChanged());
287:                assertFalse("armed", menuItem.isArmed());
288:                assertFalse("armed", menuItem.getModel().isArmed());
289:                listener.reset();
290:            }
291:
292:            /*
293:             * Test method for 'javax.swing.JMenuItem.isArmed()'
294:             */
295:            public void testIsArmed() {
296:                assertFalse("armed", menuItem.isArmed());
297:            }
298:
299:            /*
300:             * Test method for 'javax.swing.JMenuItem.setAccelerator(KeyStroke)'
301:             */
302:            public void testSetAccelerator() {
303:                PropertyChangeController listener = new PropertyChangeController();
304:                KeyStroke accelerator1 = KeyStroke.getKeyStroke('a');
305:                KeyStroke accelerator2 = KeyStroke.getKeyStroke('b');
306:                menuItem.setAccelerator(null);
307:                menuItem.addPropertyChangeListener(listener);
308:                menuItem.setAccelerator(accelerator1);
309:                listener.checkPropertyFired(menuItem, "accelerator", null,
310:                        accelerator1);
311:                assertEquals("accelerator", accelerator1, menuItem
312:                        .getAccelerator());
313:                listener.reset();
314:                menuItem.setAccelerator(accelerator2);
315:                listener.checkPropertyFired(menuItem, "accelerator",
316:                        accelerator1, accelerator2);
317:                assertEquals("accelerator", accelerator2, menuItem
318:                        .getAccelerator());
319:                listener.reset();
320:                menuItem.setAccelerator(accelerator2);
321:                assertFalse("event's not been fired ", listener.isChanged());
322:            }
323:
324:            /*
325:             * Test method for 'javax.swing.JMenuItem.getAccelerator()'
326:             */
327:            public void testGetAccelerator() {
328:                assertNull("accelerator", menuItem.getAccelerator());
329:            }
330:
331:            /*
332:             * Test method for 'javax.swing.JMenuItem.fireMenuDragMouseEntered(MenuDragMouseEvent)'
333:             */
334:            public void testFireMenuDragMouseEntered() {
335:                MenuDragMouseEvent event1 = new MenuDragMouseEvent(menuItem, 0,
336:                        0, 0, 0, 0, 0, false, new MenuElement[0],
337:                        new MenuSelectionManager());
338:                ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener();
339:                ConcreteMenuDragMouseListener listener2 = new ConcreteMenuDragMouseListener();
340:                menuItem.addMenuDragMouseListener(listener1);
341:                menuItem.addMenuDragMouseListener(listener2);
342:                menuItem.fireMenuDragMouseEntered(event1);
343:                assertEquals("event fired properly ", "entered",
344:                        listener1.event);
345:                assertEquals("event fired properly ", "entered",
346:                        listener2.event);
347:                assertSame("one event fired ", listener1.event, listener2.event);
348:                menuItem.fireMenuDragMouseEntered(event1);
349:                assertEquals("event fired properly ", "entered",
350:                        listener1.event);
351:                assertEquals("event fired properly ", "entered",
352:                        listener2.event);
353:                assertSame("one event fired ", listener1.event, listener2.event);
354:            }
355:
356:            /*
357:             * Test method for 'javax.swing.JMenuItem.fireMenuDragMouseExited(MenuDragMouseEvent)'
358:             */
359:            public void testFireMenuDragMouseExited() {
360:                MenuDragMouseEvent event1 = new MenuDragMouseEvent(menuItem, 0,
361:                        0, 0, 0, 0, 0, false, new MenuElement[0],
362:                        new MenuSelectionManager());
363:                ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener();
364:                ConcreteMenuDragMouseListener listener2 = new ConcreteMenuDragMouseListener();
365:                menuItem.addMenuDragMouseListener(listener1);
366:                menuItem.addMenuDragMouseListener(listener2);
367:                menuItem.fireMenuDragMouseExited(event1);
368:                assertEquals("event fired properly ", "exited", listener1.event);
369:                assertEquals("event fired properly ", "exited", listener2.event);
370:                assertSame("one event fired ", listener1.event, listener2.event);
371:                menuItem.fireMenuDragMouseExited(event1);
372:                assertEquals("event fired properly ", "exited", listener1.event);
373:                assertEquals("event fired properly ", "exited", listener2.event);
374:                assertSame("one event fired ", listener1.event, listener2.event);
375:            }
376:
377:            /*
378:             * Test method for 'javax.swing.JMenuItem.fireMenuDragMouseDragged(MenuDragMouseEvent)'
379:             */
380:            public void testFireMenuDragMouseDragged() {
381:                MenuDragMouseEvent event1 = new MenuDragMouseEvent(menuItem, 0,
382:                        0, 0, 0, 0, 0, false, new MenuElement[0],
383:                        new MenuSelectionManager());
384:                ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener();
385:                ConcreteMenuDragMouseListener listener2 = new ConcreteMenuDragMouseListener();
386:                menuItem.addMenuDragMouseListener(listener1);
387:                menuItem.addMenuDragMouseListener(listener2);
388:                menuItem.fireMenuDragMouseDragged(event1);
389:                assertEquals("event fired properly ", "dragged",
390:                        listener1.event);
391:                assertEquals("event fired properly ", "dragged",
392:                        listener2.event);
393:                menuItem.fireMenuDragMouseDragged(event1);
394:                assertEquals("event fired properly ", "dragged",
395:                        listener1.event);
396:                assertEquals("event fired properly ", "dragged",
397:                        listener2.event);
398:            }
399:
400:            /*
401:             * Test method for 'javax.swing.JMenuItem.fireMenuDragMouseReleased(MenuDragMouseEvent)'
402:             */
403:            public void testFireMenuDragMouseReleased() {
404:                MenuDragMouseEvent event1 = new MenuDragMouseEvent(menuItem, 0,
405:                        0, 0, 0, 0, 0, false, new MenuElement[0],
406:                        new MenuSelectionManager());
407:                ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener();
408:                ConcreteMenuDragMouseListener listener2 = new ConcreteMenuDragMouseListener();
409:                menuItem.addMenuDragMouseListener(listener1);
410:                menuItem.addMenuDragMouseListener(listener2);
411:                menuItem.fireMenuDragMouseReleased(event1);
412:                assertEquals("event fired properly ", "released",
413:                        listener1.event);
414:                assertEquals("event fired properly ", "released",
415:                        listener2.event);
416:                menuItem.fireMenuDragMouseReleased(event1);
417:                assertEquals("event fired properly ", "released",
418:                        listener1.event);
419:                assertEquals("event fired properly ", "released",
420:                        listener2.event);
421:            }
422:
423:            /*
424:             * Test method for 'javax.swing.JMenuItem.fireMenuKeyPressed(MenuKeyEvent)'
425:             */
426:            public void testFireMenuKeyPressed() {
427:                MenuKeyEvent event1 = new MenuKeyEvent(menuItem, 0, 0, 0, 0,
428:                        'a', new MenuElement[0], new MenuSelectionManager());
429:                ConcreteMenuKeyListener listener1 = new ConcreteMenuKeyListener();
430:                ConcreteMenuKeyListener listener2 = new ConcreteMenuKeyListener();
431:                menuItem.addMenuKeyListener(listener1);
432:                menuItem.addMenuKeyListener(listener2);
433:                menuItem.fireMenuKeyPressed(event1);
434:                assertEquals("event fired properly ", "pressed",
435:                        listener1.event);
436:                assertEquals("event fired properly ", "pressed",
437:                        listener2.event);
438:                menuItem.fireMenuKeyPressed(event1);
439:                assertEquals("event fired properly ", "pressed",
440:                        listener1.event);
441:                assertEquals("event fired properly ", "pressed",
442:                        listener2.event);
443:            }
444:
445:            /*
446:             * Test method for 'javax.swing.JMenuItem.fireMenuKeyReleased(MenuKeyEvent)'
447:             */
448:            public void testFireMenuKeyReleased() {
449:                MenuKeyEvent event1 = new MenuKeyEvent(menuItem, 0, 0, 0, 0,
450:                        'a', new MenuElement[0], new MenuSelectionManager());
451:                ConcreteMenuKeyListener listener1 = new ConcreteMenuKeyListener();
452:                ConcreteMenuKeyListener listener2 = new ConcreteMenuKeyListener();
453:                menuItem.addMenuKeyListener(listener1);
454:                menuItem.addMenuKeyListener(listener2);
455:                menuItem.fireMenuKeyReleased(event1);
456:                assertEquals("event fired properly ", "released",
457:                        listener1.event);
458:                assertEquals("event fired properly ", "released",
459:                        listener2.event);
460:                assertSame("one event fired ", listener1.event, listener2.event);
461:                menuItem.fireMenuKeyReleased(event1);
462:                assertEquals("event fired properly ", "released",
463:                        listener1.event);
464:                assertEquals("event fired properly ", "released",
465:                        listener2.event);
466:                assertSame("one event fired ", listener1.event, listener2.event);
467:            }
468:
469:            /*
470:             * Test method for 'javax.swing.JMenuItem.fireMenuKeyTyped(MenuKeyEvent)'
471:             */
472:            public void testFireMenuKeyTyped() {
473:                MenuKeyEvent event1 = new MenuKeyEvent(menuItem, 0, 0, 0, 0,
474:                        'a', new MenuElement[0], new MenuSelectionManager());
475:                ConcreteMenuKeyListener listener1 = new ConcreteMenuKeyListener();
476:                ConcreteMenuKeyListener listener2 = new ConcreteMenuKeyListener();
477:                menuItem.addMenuKeyListener(listener1);
478:                menuItem.addMenuKeyListener(listener2);
479:                menuItem.fireMenuKeyTyped(event1);
480:                assertEquals("event fired properly ", "typed", listener1.event);
481:                assertEquals("event fired properly ", "typed", listener2.event);
482:                assertSame("one event fired ", listener1.event, listener2.event);
483:                menuItem.fireMenuKeyTyped(event1);
484:                assertEquals("event fired properly ", "typed", listener1.event);
485:                assertEquals("event fired properly ", "typed", listener2.event);
486:                assertSame("one event fired ", listener1.event, listener2.event);
487:            }
488:
489:            /*
490:             * Test method for 'javax.swing.JMenuItem.addMenuDragMouseListener(MenuDragMouseListener)'
491:             */
492:            public void testAddGetRemoveMenuDragMouseListener() {
493:                MenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener();
494:                MenuDragMouseListener listener2 = new ConcreteMenuDragMouseListener();
495:                MenuDragMouseListener listener3 = new ConcreteMenuDragMouseListener();
496:                EventListener[] listenersArray = null;
497:                listenersArray = menuItem.getMenuDragMouseListeners();
498:                int initialValue = listenersArray.length;
499:                menuItem.addMenuDragMouseListener(listener1);
500:                menuItem.addMenuDragMouseListener(listener2);
501:                menuItem.addMenuDragMouseListener(listener2);
502:                listenersArray = menuItem.getMenuDragMouseListeners();
503:                assertEquals(initialValue + 3, listenersArray.length);
504:                menuItem.removeMenuDragMouseListener(listener1);
505:                menuItem.addMenuDragMouseListener(listener3);
506:                menuItem.addMenuDragMouseListener(listener3);
507:                listenersArray = menuItem.getMenuDragMouseListeners();
508:                assertEquals(initialValue + 4, listenersArray.length);
509:                menuItem.removeMenuDragMouseListener(listener3);
510:                menuItem.removeMenuDragMouseListener(listener3);
511:                listenersArray = menuItem.getMenuDragMouseListeners();
512:                assertEquals(initialValue + 2, listenersArray.length);
513:                menuItem.removeMenuDragMouseListener(listener2);
514:                menuItem.removeMenuDragMouseListener(listener2);
515:                listenersArray = menuItem.getMenuDragMouseListeners();
516:                assertEquals(initialValue, listenersArray.length);
517:            }
518:
519:            /*
520:             * Test method for 'javax.swing.JMenuItem.addMenuKeyListener(MenuKeyListener)'
521:             */
522:            public void testAddGetRemoveMenuKeyListener() {
523:                MenuKeyListener listener1 = new ConcreteMenuKeyListener();
524:                MenuKeyListener listener2 = new ConcreteMenuKeyListener();
525:                MenuKeyListener listener3 = new ConcreteMenuKeyListener();
526:                EventListener[] listenersArray = null;
527:                listenersArray = menuItem.getMenuKeyListeners();
528:                int initialValue = listenersArray.length;
529:                menuItem.addMenuKeyListener(listener1);
530:                menuItem.addMenuKeyListener(listener2);
531:                menuItem.addMenuKeyListener(listener2);
532:                listenersArray = menuItem.getMenuKeyListeners();
533:                assertEquals(initialValue + 3, listenersArray.length);
534:                menuItem.removeMenuKeyListener(listener1);
535:                menuItem.addMenuKeyListener(listener3);
536:                menuItem.addMenuKeyListener(listener3);
537:                listenersArray = menuItem.getMenuKeyListeners();
538:                assertEquals(initialValue + 4, listenersArray.length);
539:                menuItem.removeMenuKeyListener(listener3);
540:                menuItem.removeMenuKeyListener(listener3);
541:                listenersArray = menuItem.getMenuKeyListeners();
542:                assertEquals(initialValue + 2, listenersArray.length);
543:                menuItem.removeMenuKeyListener(listener2);
544:                menuItem.removeMenuKeyListener(listener2);
545:                listenersArray = menuItem.getMenuKeyListeners();
546:                assertEquals(initialValue, listenersArray.length);
547:            }
548:
549:            /*
550:             * Test method for 'javax.swing.JMenuItem.getComponent()'
551:             */
552:            public void testGetComponent() {
553:                assertSame(menuItem, menuItem.getComponent());
554:            }
555:
556:            /*
557:             * Test method for 'javax.swing.JMenuItem.getSubElements()'
558:             */
559:            public void testGetSubElements() {
560:                assertEquals(0, menuItem.getSubElements().length);
561:            }
562:
563:            /*
564:             * Test method for 'javax.swing.JMenuItem.menuSelectionChanged(boolean)'
565:             */
566:            public void testMenuSelectionChanged() {
567:                assertFalse(menuItem.isArmed());
568:                menuItem.menuSelectionChanged(true);
569:                assertTrue(menuItem.isArmed());
570:                menuItem.menuSelectionChanged(false);
571:                assertFalse(menuItem.isArmed());
572:            }
573:
574:            /*
575:             * Test method for 'javax.swing.JMenuItem.processMenuKeyEvent(MenuKeyEvent)'
576:             */
577:            public void testProcessMenuKeyEvent() {
578:                final MenuSelectionManager menuSelectionManager = new MenuSelectionManager();
579:                MenuKeyEvent event1 = new MenuKeyEvent(menuItem,
580:                        KeyEvent.KEY_PRESSED, 0, 0, 0, 'a', new MenuElement[0],
581:                        menuSelectionManager);
582:                MenuKeyEvent event2 = new MenuKeyEvent(menuItem,
583:                        KeyEvent.KEY_RELEASED, 0, 0, 0, 'b',
584:                        new MenuElement[0], menuSelectionManager);
585:                MenuKeyEvent event3 = new MenuKeyEvent(menuItem,
586:                        KeyEvent.KEY_TYPED, 0, 0, 0, 'c', new MenuElement[0],
587:                        menuSelectionManager);
588:                ConcreteMenuKeyListener listener1 = new ConcreteMenuKeyListener();
589:                menuItem.addMenuKeyListener(listener1);
590:                menuItem.processMenuKeyEvent(event1);
591:                assertEquals("event fired properly ", "pressed",
592:                        listener1.event);
593:                menuItem.processMenuKeyEvent(event2);
594:                assertEquals("event fired properly ", "released",
595:                        listener1.event);
596:                menuItem.processMenuKeyEvent(event3);
597:                assertEquals("event fired properly ", "typed", listener1.event);
598:            }
599:
600:            /*
601:             * Test method for 'javax.swing.JMenuItem.processKeyEvent(KeyEvent, MenuElement[], MenuSelectionManager)'
602:             */
603:            public void testProcessKeyEventKeyEventMenuElementArrayMenuSelectionManager() {
604:                final MenuSelectionManager menuSelectionManager = new MenuSelectionManager();
605:                KeyEvent event1 = new KeyEvent(menuItem, KeyEvent.KEY_PRESSED,
606:                        0, 0, 0, 'a');
607:                KeyEvent event2 = new KeyEvent(menuItem, KeyEvent.KEY_RELEASED,
608:                        0, 0, 0, 'b');
609:                KeyEvent event3 = new KeyEvent(menuItem, KeyEvent.KEY_TYPED, 0,
610:                        0, 0, 'c');
611:                ConcreteMenuKeyListener listener1 = new ConcreteMenuKeyListener();
612:                menuItem.addMenuKeyListener(listener1);
613:                menuItem.processKeyEvent(event1, new MenuElement[0],
614:                        menuSelectionManager);
615:                assertEquals("event fired properly ", "pressed",
616:                        listener1.event);
617:                menuItem.processKeyEvent(event2, new MenuElement[] {},
618:                        menuSelectionManager);
619:                assertEquals("event fired properly ", "released",
620:                        listener1.event);
621:                menuItem.processKeyEvent(event3, new MenuElement[] {},
622:                        menuSelectionManager);
623:                assertEquals("event fired properly ", "typed", listener1.event);
624:            }
625:
626:            /*
627:             * Test method for 'javax.swing.JMenuItem.processMenuDragMouseEvent(MenuDragMouseEvent)'
628:             */
629:            public void testProcessMenuDragMouseEvent() {
630:                MenuDragMouseEvent event1 = new MenuDragMouseEvent(menuItem,
631:                        MouseEvent.MOUSE_DRAGGED, 0, 0, 10, 10, 1, true,
632:                        new MenuElement[0], new MenuSelectionManager());
633:                MenuDragMouseEvent event2 = new MenuDragMouseEvent(menuItem,
634:                        MouseEvent.MOUSE_EXITED, 0, 0, 10, 10, 1, true,
635:                        new MenuElement[] { menuItem },
636:                        new MenuSelectionManager());
637:                MenuDragMouseEvent event3 = new MenuDragMouseEvent(
638:                        new JButton(), MouseEvent.MOUSE_ENTERED, 0, 0, 10, 10,
639:                        1, true, new MenuElement[] { menuItem },
640:                        new MenuSelectionManager());
641:                MenuDragMouseEvent event4 = new MenuDragMouseEvent(menuItem,
642:                        MouseEvent.MOUSE_RELEASED, 0, MouseEvent.BUTTON1, 10,
643:                        10, 1, false, new MenuElement[] {},
644:                        new MenuSelectionManager());
645:                ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener();
646:                menuItem.addMenuDragMouseListener(listener1);
647:                menuItem.processMenuDragMouseEvent(event2);
648:                assertEquals("exited", listener1.event);
649:                menuItem.processMenuDragMouseEvent(event1);
650:                assertEquals("dragged", listener1.event);
651:                menuItem.processMenuDragMouseEvent(event3);
652:                assertEquals("entered", listener1.event);
653:                listener1.event = null;
654:                menuItem.processMenuDragMouseEvent(event4);
655:                assertNull(listener1.event);
656:                menuItem.processMenuDragMouseEvent(event1);
657:                assertEquals("dragged", listener1.event);
658:                listener1.event = null;
659:                menuItem.processMenuDragMouseEvent(event4);
660:                assertEquals("released", listener1.event);
661:            }
662:
663:            /*
664:             * Test method for 'javax.swing.JMenuItem.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)'
665:             */
666:            public void testProcessMouseEventMouseEventMenuElementArrayMenuSelectionManager() {
667:                MouseEvent event1 = new MouseEvent(menuItem,
668:                        MouseEvent.MOUSE_DRAGGED, 0, 0, 10, 10, 1, true);
669:                MouseEvent event2 = new MouseEvent(menuItem,
670:                        MouseEvent.MOUSE_EXITED, 0, 0, 10, 10, 1, true);
671:                MouseEvent event3 = new MouseEvent(new JButton(),
672:                        MouseEvent.MOUSE_ENTERED, 0, 0, 10, 10, 1, true);
673:                MouseEvent event4 = new MouseEvent(menuItem,
674:                        MouseEvent.MOUSE_RELEASED, 0, MouseEvent.BUTTON1, 10,
675:                        10, 1, false);
676:                ConcreteMenuDragMouseListener listener1 = new ConcreteMenuDragMouseListener();
677:                menuItem.addMenuDragMouseListener(listener1);
678:                menuItem.processMouseEvent(event2, new MenuElement[] {},
679:                        new MenuSelectionManager());
680:                assertEquals("exited", listener1.event);
681:                menuItem.processMouseEvent(event1, new MenuElement[] {},
682:                        new MenuSelectionManager());
683:                assertEquals("dragged", listener1.event);
684:                menuItem.processMouseEvent(event3, new MenuElement[] {},
685:                        new MenuSelectionManager());
686:                assertEquals("entered", listener1.event);
687:                listener1.event = null;
688:                menuItem.processMouseEvent(event4, new MenuElement[] {},
689:                        new MenuSelectionManager());
690:                assertNull(listener1.event);
691:                menuItem.processMouseEvent(event1, new MenuElement[] {},
692:                        new MenuSelectionManager());
693:                assertEquals("dragged", listener1.event);
694:                listener1.event = null;
695:                menuItem.processMouseEvent(event4, new MenuElement[] {},
696:                        new MenuSelectionManager());
697:                assertEquals("released", listener1.event);
698:            }
699:
700:            @Override
701:            public void testGetUI() {
702:                assertNotNull("ui is returned ", menuItem.getUI());
703:            }
704:
705:            @Override
706:            public void testIsFocusPainted() {
707:                assertFalse("default FocusPainted", menuItem.isFocusPainted());
708:            }
709:
710:            @Override
711:            public void testGetHorizontalAlignment() {
712:            }
713:
714:            @Override
715:            public void testConfigurePropertiesFromAction_ShortDescription() {
716:            }
717:
718:            @Override
719:            public void testConfigurePropertiesFromAction() {
720:                Icon icon1 = createNewIcon();
721:                Icon icon2 = createNewIcon();
722:                KeyStroke ks1 = KeyStroke.getKeyStroke('a');
723:                KeyStroke ks2 = KeyStroke.getKeyStroke('b');
724:                String text1 = "texttext1";
725:                String text2 = "texttext2";
726:                String text3 = "texttext3";
727:                String text4 = "texttext4";
728:                AbstractAction action1 = new AbstractAction(text1, icon1) {
729:                    public void actionPerformed(final ActionEvent event) {
730:                    }
731:                };
732:                AbstractAction action2 = new AbstractAction(text2, icon2) {
733:                    public void actionPerformed(final ActionEvent event) {
734:                    }
735:                };
736:                action1.setEnabled(true);
737:                action1.putValue(Action.SHORT_DESCRIPTION, text3);
738:                action1.putValue(Action.MNEMONIC_KEY, new Integer(1));
739:                button.setAction(action1);
740:                assertEquals("action ", action1, button.getAction());
741:                assertTrue("enabled ", button.isEnabled());
742:                assertTrue("enabled ", action1.isEnabled());
743:                action1.setEnabled(false);
744:                button.isEnabled();
745:                assertFalse("enabled ", button.isEnabled());
746:                assertFalse("enabled ", action1.isEnabled());
747:                assertEquals("icon ", icon1, button.getIcon());
748:                action1.putValue(Action.SMALL_ICON, icon2);
749:                assertEquals("icon ", icon2, button.getIcon());
750:                button.setIcon(icon2);
751:                action1.putValue(Action.SMALL_ICON, null);
752:                assertNull("icon ", button.getIcon());
753:                if (isHarmony()) {
754:                    assertEquals("mnemonic ", 1, button.getMnemonic());
755:                    action1.putValue(Action.MNEMONIC_KEY, new Integer(27));
756:                    assertEquals("mnemonic ", 27, button.getMnemonic());
757:                    action1.putValue(Action.ACCELERATOR_KEY, ks1);
758:                    assertEquals("accelerator ", ks1, menuItem.getAccelerator());
759:                }
760:                assertEquals("text ", text1, button.getText());
761:                action1.putValue(Action.NAME, text2);
762:                assertEquals("text ", text2, button.getText());
763:                if (isHarmony()) {
764:                    assertEquals("ToolTipText ", text3, button.getToolTipText());
765:                    action1.putValue(Action.SHORT_DESCRIPTION, text4);
766:                    assertEquals("ToolTipText ", text4, button.getToolTipText());
767:                }
768:                action2.putValue(Action.ACCELERATOR_KEY, ks2);
769:                button.setAction(action2);
770:                action1.putValue(Action.SHORT_DESCRIPTION, text4);
771:                assertNull("ToolTipText ", button.getToolTipText());
772:                if (isHarmony()) {
773:                    action2.putValue(Action.SHORT_DESCRIPTION, text4);
774:                    assertEquals("ToolTipText ", text4, button.getToolTipText());
775:                    assertEquals("accelerator ", ks2, menuItem.getAccelerator());
776:                }
777:            }
778:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.