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

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


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Vadim L. Bogdanov
019:         * @version $Revision$
020:         */package javax.swing;
021:
022:        import java.awt.BorderLayout;
023:        import java.awt.Dialog;
024:        import java.awt.FlowLayout;
025:        import java.awt.Frame;
026:        import java.awt.GraphicsConfiguration;
027:        import java.awt.GraphicsEnvironment;
028:        import java.awt.IllegalComponentStateException;
029:        import java.awt.KeyboardFocusManager;
030:        import java.awt.LayoutManager;
031:        import java.awt.event.WindowEvent;
032:        import java.beans.PropertyChangeEvent;
033:        import java.beans.PropertyChangeListener;
034:        import javax.accessibility.AccessibleContext;
035:        import javax.accessibility.AccessibleRole;
036:        import javax.accessibility.AccessibleState;
037:
038:        public class JDialogTest extends SwingTestCase {
039:            /*
040:             * This class is used to test that some methods were called.
041:             */
042:            private static class TestDialog extends JDialog {
043:                private static final long serialVersionUID = 1L;
044:
045:                public static boolean createRootPaneCalled = false;
046:
047:                public static boolean setRootPaneCalled = false;
048:
049:                public boolean disposeCalled = false;
050:
051:                @Override
052:                public JRootPane createRootPane() {
053:                    createRootPaneCalled = true;
054:                    return super .createRootPane();
055:                }
056:
057:                @Override
058:                public void setRootPane(final JRootPane root) {
059:                    setRootPaneCalled = true;
060:                    super .setRootPane(root);
061:                }
062:
063:                public static void initStaticVars() {
064:                    createRootPaneCalled = false;
065:                    setRootPaneCalled = false;
066:                }
067:
068:                @Override
069:                public void dispose() {
070:                    disposeCalled = true;
071:                    super .dispose();
072:                }
073:            }
074:
075:            /*
076:             * This class is used to test that some property is (or is not) a bound property
077:             */
078:            private class MyPropertyChangeListener implements 
079:                    PropertyChangeListener {
080:                public boolean ok;
081:
082:                MyPropertyChangeListener() {
083:                    ok = false;
084:                }
085:
086:                public void propertyChange(final PropertyChangeEvent e) {
087:                    ok = true;
088:                }
089:            }
090:
091:            private JDialog dialog;
092:
093:            /*
094:             * Constructor
095:             */
096:            public JDialogTest(final String name) {
097:                super (name);
098:            }
099:
100:            /*
101:             * @see TestCase#setUp()
102:             */
103:            @Override
104:            protected void setUp() throws Exception {
105:                super .setUp();
106:                dialog = new JDialog();
107:                TestDialog.initStaticVars();
108:            }
109:
110:            /*
111:             * @see TestCase#tearDown()
112:             */
113:            @Override
114:            protected void tearDown() throws Exception {
115:                super .tearDown();
116:                if (dialog.isDisplayable()) {
117:                    dialog.dispose();
118:                }
119:            }
120:
121:            /*
122:             * Auxiliary method to check JDialog correctness after constructor's call.
123:             */
124:            protected void checkDialogCorrectness(final JDialog dialog,
125:                    final String title, final boolean modal) {
126:                assertFalse("JDialog is invisible by default", dialog
127:                        .isVisible());
128:                assertTrue("locale is set", dialog.getLocale() == JComponent
129:                        .getDefaultLocale());
130:                assertTrue("owner is not null", dialog.getOwner() != null);
131:                assertTrue("isModal is set", dialog.isModal() == modal);
132:                assertTrue("title is set", dialog.getTitle() == title);
133:            }
134:
135:            /*
136:             * Class under test for void JDialog()
137:             */
138:            public void testJDialog() {
139:                dialog = new JDialog();
140:                // title == null, isModal() == false
141:                checkDialogCorrectness(dialog, null, false);
142:            }
143:
144:            /*
145:             * Class under test for void dialogInit()
146:             */
147:            public void testDialogInit() {
148:                TestDialog dialog = new TestDialog();
149:                assertTrue("onwer is not null", dialog.getOwner() != null);
150:                assertTrue("rootPaneCheckingEnabled is true", dialog
151:                        .isRootPaneCheckingEnabled());
152:                assertTrue("layout is not null", dialog.getLayout() != null);
153:                assertTrue("rootPane is not null", dialog.getRootPane() != null);
154:                assertTrue("locale is set", dialog.getLocale() == JComponent
155:                        .getDefaultLocale());
156:                assertFalse("defaultLookAndFeelDecorated is false", JDialog
157:                        .isDefaultLookAndFeelDecorated());
158:                assertFalse("isUndecorated is false", dialog.isUndecorated());
159:                assertTrue(
160:                        "rootPane.windowDecorationStyle is NONE",
161:                        dialog.getRootPane().getWindowDecorationStyle() == JRootPane.NONE);
162:                // test that defaultFocusTraversalPolicy is set
163:                //dialog.setFocusTraversalPolicy(null);
164:                //dialog.dialogInit();
165:                assertTrue("focusTraversalPolicy is set correctly", dialog
166:                        .getFocusTraversalPolicy() == KeyboardFocusManager
167:                        .getCurrentKeyboardFocusManager()
168:                        .getDefaultFocusTraversalPolicy());
169:                assertTrue("focusTraversalPolicy is set", dialog
170:                        .isFocusTraversalPolicySet());
171:                assertTrue(dialog.isFocusCycleRoot());
172:                assertFalse(dialog.isFocusTraversalPolicyProvider());
173:                JDialog.setDefaultLookAndFeelDecorated(true);
174:                dialog.dialogInit();
175:                assertTrue("isUndecorated is true", dialog.isUndecorated());
176:                assertTrue(
177:                        "rootPane.windowDecorationStyle is PLAIN_DIALOG",
178:                        dialog.getRootPane().getWindowDecorationStyle() == JRootPane.PLAIN_DIALOG);
179:                // restore default value
180:                JDialog.setDefaultLookAndFeelDecorated(false);
181:            }
182:
183:            /*
184:             * Class under test for
185:             *     void setDefaultCloseOperation(int operation)
186:             *     int getDefaultCloseOperation()
187:             */
188:            public void testSetGetDefaultCloseOperation() {
189:                // default value is JDialog.HIDE_ON_CLOSE
190:                assertEquals(WindowConstants.HIDE_ON_CLOSE, dialog
191:                        .getDefaultCloseOperation());
192:                // test setting valid value
193:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
194:                dialog.addPropertyChangeListener("defaultCloseOperation",
195:                        listener);
196:                dialog
197:                        .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
198:                assertEquals(WindowConstants.DISPOSE_ON_CLOSE, dialog
199:                        .getDefaultCloseOperation());
200:                // it is not a bound property
201:                assertFalse("defaultCloseOperation is a bound property",
202:                        listener.ok);
203:                // test setting invalid value
204:                boolean ok = false;
205:                try {
206:                    dialog.setDefaultCloseOperation(101); // invalid value
207:                } catch (IllegalArgumentException e) {
208:                    ok = true;
209:                } finally {
210:                    // exception is not thrown
211:                    assertFalse("exception was not thrown", ok);
212:                    //  is is set
213:                    assertTrue("invalid value is set", dialog
214:                            .getDefaultCloseOperation() == 101);
215:                }
216:            }
217:
218:            /*
219:             * Class under test for
220:             *     static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)
221:             *     static boolean isDefaultLookAndFeelDecorated()
222:             */
223:            public void testSetIsDefaultLookAndFeelDecorated() {
224:                // test for default value
225:                assertFalse(JDialog.isDefaultLookAndFeelDecorated());
226:                JDialog.setDefaultLookAndFeelDecorated(true);
227:                assertTrue(JDialog.isDefaultLookAndFeelDecorated());
228:                // restore default value
229:                JDialog.setDefaultLookAndFeelDecorated(false);
230:            }
231:
232:            /*
233:             * Class under test for
234:             *     void setRootPaneCheckingEnabled(boolean enabled)
235:             *     boolean isRootPaneCheckingEnabled()
236:             */
237:            public void testSetIsRootPaneCheckingEnabled() {
238:                TestDialog dialog = new TestDialog();
239:                assertTrue("rootPaneCheckingEnabled is true by default", dialog
240:                        .isRootPaneCheckingEnabled());
241:                dialog.setRootPaneCheckingEnabled(false);
242:                assertFalse("rootPaneCheckingEnabled is set to false", dialog
243:                        .isRootPaneCheckingEnabled());
244:            }
245:
246:            /*
247:             * Class under test for void JDialog(Frame, String, boolean, GraphicsConfiguration)
248:             */
249:            public void testJDialogFrameStringbooleanGraphicsConfiguration() {
250:                Frame owner = new Frame();
251:                final GraphicsConfiguration gc = GraphicsEnvironment
252:                        .getLocalGraphicsEnvironment().getDefaultScreenDevice()
253:                        .getDefaultConfiguration();
254:                // test with corrent owner, correct title, modal == false, correct gc
255:                dialog = new JDialog(owner, "Test JDialog", false, gc);
256:                // title is set, isModal() == false
257:                checkDialogCorrectness(dialog, "Test JDialog", false);
258:                assertTrue("owner is set", dialog.getOwner() == owner);
259:                assertTrue("gc is set", dialog.getGraphicsConfiguration() == gc);
260:                // test with corrent owner, correct title, modal == false, incorrect gc
261:                dialog = new JDialog(owner, "Test JDialog", false, null);
262:                // title is set, isModal() == false
263:                checkDialogCorrectness(dialog, "Test JDialog", false);
264:                assertTrue("owner is set", dialog.getOwner() == owner);
265:                assertTrue("gc is set from the owner", dialog
266:                        .getGraphicsConfiguration() == dialog.getOwner()
267:                        .getGraphicsConfiguration());
268:                // test with null owner, correct title, modal == false, incorrect gc
269:                dialog = new JDialog((Frame) null, "Test JDialog", false, null);
270:                // title is set, isModal() == false
271:                checkDialogCorrectness(dialog, "Test JDialog", false);
272:                assertTrue("owner is set", dialog.getOwner() != null);
273:                // this case is not described in docs, but gc definitely can't be null
274:                assertTrue("gc is set",
275:                        dialog.getGraphicsConfiguration() != null);
276:            }
277:
278:            /*
279:             * Class under test for void JDialog(Dialog, String, boolean, GraphicsConfiguration)
280:             */
281:            public void testJDialogDialogStringbooleanGraphicsConfiguration() {
282:                Dialog owner = new Dialog(new Frame());
283:                final GraphicsConfiguration gc = GraphicsEnvironment
284:                        .getLocalGraphicsEnvironment().getDefaultScreenDevice()
285:                        .getDefaultConfiguration();
286:                // test with corrent owner, correct title, modal == true, correct gc
287:                dialog = new JDialog(owner, "Test JDialog", true, gc);
288:                // title is set, isModal() == true
289:                checkDialogCorrectness(dialog, "Test JDialog", true);
290:                assertTrue("owner is set", dialog.getOwner() == owner);
291:                assertTrue("gc is set", dialog.getGraphicsConfiguration() == gc);
292:                // test with corrent owner, correct title, modal == false, incorrect gc
293:                dialog = new JDialog(owner, "Test JDialog", false, null);
294:                // title is set, isModal() == false
295:                checkDialogCorrectness(dialog, "Test JDialog", false);
296:                assertTrue("owner is set", dialog.getOwner() == owner);
297:                assertTrue("gc is set from the owner", dialog
298:                        .getGraphicsConfiguration() == dialog.getOwner()
299:                        .getGraphicsConfiguration());
300:            }
301:
302:            /*
303:             * Class under test for void JDialog(Frame, String, boolean)
304:             */
305:            public void testJDialogFrameStringboolean() {
306:                Frame owner = new Frame();
307:                // test with corrent owner, correct title, modal == false
308:                dialog = new JDialog(owner, "Test JDialog", false);
309:                // title is set, isModal() == false
310:                checkDialogCorrectness(dialog, "Test JDialog", false);
311:                assertTrue("owner is set", dialog.getOwner() == owner);
312:                // test with corrent owner, correct title, modal == true
313:                dialog = new JDialog(owner, "Test JDialog", true);
314:                // title is set, isModal() == true
315:                checkDialogCorrectness(dialog, "Test JDialog", true);
316:                assertTrue("owner is set", dialog.getOwner() == owner);
317:                // test with corrent owner, incorrect title, modal == true
318:                dialog = new JDialog(owner, null, true);
319:                // title is not set, isModal() == true
320:                checkDialogCorrectness(dialog, null, true);
321:                assertTrue("owner is set", dialog.getOwner() == owner);
322:                // test with incorrent owner, correct title, modal == true
323:                dialog = new JDialog((Frame) null, "Test JDialog", true);
324:                checkDialogCorrectness(dialog, "Test JDialog", true);
325:            }
326:
327:            /*
328:             * Class under test for void JDialog(Frame, String)
329:             */
330:            public void testJDialogFrameString() {
331:                Frame owner = new Frame();
332:                // test with corrent owner, correct title
333:                dialog = new JDialog(owner, "Test JDialog");
334:                // title is set, isModal() == false
335:                checkDialogCorrectness(dialog, "Test JDialog", false);
336:                assertTrue("owner is set", dialog.getOwner() == owner);
337:                // test with corrent owner, incorrect title
338:                dialog = new JDialog(owner, null);
339:                // title is not set, isModal() == false
340:                checkDialogCorrectness(dialog, null, false);
341:                assertTrue("owner is set", dialog.getOwner() == owner);
342:                // test with incorrent owner, correct title
343:                dialog = new JDialog((Frame) null, "Test JDialog");
344:                checkDialogCorrectness(dialog, "Test JDialog", false);
345:            }
346:
347:            /*
348:             * Class under test for void JDialog(Dialog, String, boolean)
349:             */
350:            public void testJDialogDialogStringboolean() {
351:                Dialog owner = new Dialog(new Frame());
352:                // test with corrent owner, correct title, modal == false
353:                dialog = new JDialog(owner, "Test JDialog", false);
354:                // title is set, isModal() == false
355:                checkDialogCorrectness(dialog, "Test JDialog", false);
356:                assertTrue("owner is set", dialog.getOwner() == owner);
357:                // test with corrent owner, correct title, modal == true
358:                dialog = new JDialog(owner, "Test JDialog", true);
359:                // title not set, isModal() == true
360:                checkDialogCorrectness(dialog, "Test JDialog", true);
361:                assertTrue("owner is set", dialog.getOwner() == owner);
362:                // test with corrent owner, incorrect title, modal == true
363:                dialog = new JDialog(owner, null, true);
364:                // title is not set, isModal() == true
365:                checkDialogCorrectness(dialog, null, true);
366:                assertTrue("owner is set", dialog.getOwner() == owner);
367:                // owner cannot be null in this case
368:            }
369:
370:            /*
371:             * Class under test for void JDialog(Dialog, String)
372:             */
373:            public void testJDialogDialogString() {
374:                Dialog owner = new Dialog(new Frame());
375:                // test with corrent owner, correct title
376:                dialog = new JDialog(owner, "Test JDialog");
377:                // title is set, isModal() == false
378:                checkDialogCorrectness(dialog, "Test JDialog", false);
379:                assertTrue("owner is set", dialog.getOwner() == owner);
380:                // test with corrent owner, incorrect title
381:                dialog = new JDialog(owner, null);
382:                // title is not set, isModal() == false
383:                checkDialogCorrectness(dialog, null, false);
384:                assertTrue("owner is set", dialog.getOwner() == owner);
385:                // owner cannot be null in this case
386:            }
387:
388:            /*
389:             * Class under test for void JDialog(Frame, boolean)
390:             */
391:            public void testJDialogFrameboolean() {
392:                Frame owner = new Frame();
393:                // test with corrent owner, modal == false
394:                dialog = new JDialog(owner, false);
395:                // title == null, isModal() == false
396:                checkDialogCorrectness(dialog, null, false);
397:                assertTrue("owner is set", dialog.getOwner() == owner);
398:                // test with corrent owner, modal == true
399:                dialog = new JDialog(owner, true);
400:                // title == null, isModal() == false
401:                checkDialogCorrectness(dialog, null, true);
402:                assertTrue("owner is set", dialog.getOwner() == owner);
403:                // test with incorrect owner
404:                dialog = new JDialog((Frame) null, true);
405:                // title == null, isModal() == true
406:                checkDialogCorrectness(dialog, null, true);
407:            }
408:
409:            /*
410:             * Class under test for void JDialog(Frame)
411:             */
412:            public void testJDialogFrame() {
413:                Frame owner = new Frame();
414:                // test with corrent owner
415:                dialog = new JDialog(owner);
416:                // title == null, isModal() == false
417:                checkDialogCorrectness(dialog, null, false);
418:                assertTrue("owner is set", dialog.getOwner() == owner);
419:                // test with incorrect owner
420:                dialog = new JDialog((Frame) null);
421:                // title == null, isModal() == false
422:                checkDialogCorrectness(dialog, null, false);
423:            }
424:
425:            /*
426:             * Class under test for void JDialog(Dialog, boolean)
427:             */
428:            public void testJDialogDialogboolean() {
429:                Dialog owner = new Dialog(new Frame());
430:                // test with corrent owner, modal == false
431:                dialog = new JDialog(owner, false);
432:                // title == null, isModal() == false
433:                checkDialogCorrectness(dialog, null, false);
434:                assertTrue("owner is set", dialog.getOwner() == owner);
435:                // test with corrent owner, modal == true
436:                dialog = new JDialog(owner, true);
437:                // title == null, isModal() == true
438:                checkDialogCorrectness(dialog, null, true);
439:                assertTrue("owner is set", dialog.getOwner() == owner);
440:                // owner cannot be null in this case
441:            }
442:
443:            /*
444:             * Class under test for void JDialog(Dialog)
445:             */
446:            public void testJDialogDialog() {
447:                Dialog owner = new Dialog(new Frame());
448:                // test with corrent owner
449:                dialog = new JDialog(owner);
450:                // title == null, isModal() == false
451:                checkDialogCorrectness(dialog, null, false);
452:                assertTrue("owner is set", dialog.getOwner() == owner);
453:                // owner cannot be null in this case
454:            }
455:
456:            /*
457:             * Class under test for void addImpl(Component, Object, int)
458:             */
459:            public void testAddImpl() {
460:                TestDialog dialog = new TestDialog();
461:                JComponent comp = new JPanel();
462:                // rootPaneCheckingEnabled is true, no exception since 1.5
463:                dialog.setRootPaneCheckingEnabled(true);
464:                boolean ok = false;
465:                try {
466:                    dialog.addImpl(comp, null, 0);
467:                } catch (Error e) {
468:                    ok = true;
469:                } finally {
470:                    assertFalse("no exception", ok);
471:                    assertTrue("The component is added to contentPane", comp
472:                            .getParent() == dialog.getContentPane());
473:                }
474:                // rootPaneCheckingEnabled is false, no exception
475:                dialog.setRootPaneCheckingEnabled(false);
476:                ok = false;
477:                try {
478:                    dialog.addImpl(comp, null, 0);
479:                } catch (Error e) {
480:                    ok = true;
481:                } finally {
482:                    assertFalse("no exception", ok);
483:                    assertTrue("the component is added to JWindow", comp
484:                            .getParent() == dialog);
485:                    assertTrue("index of the component is 0", dialog
486:                            .getComponent(0) == comp);
487:                }
488:            }
489:
490:            /*
491:             * Class under test for
492:             *     void setRootPane(JRootPane)
493:             *     JRootPane getRootPane()
494:             */
495:            public void testSetGetRootPane() {
496:                TestDialog dialog = new TestDialog();
497:                assertTrue("setRootPane() is called from the constructor",
498:                        TestDialog.setRootPaneCalled);
499:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
500:                dialog.addPropertyChangeListener("rootPane", listener);
501:                JRootPane root = new JRootPane();
502:                dialog.setRootPane(root);
503:                assertTrue(dialog.getRootPane() == root);
504:                assertFalse("rootPane is not a bound property", listener.ok);
505:                // test setting rootPane to null
506:                dialog.setRootPane(null);
507:                assertNull(dialog.getRootPane());
508:                assertTrue("rootPane is removed from the container", dialog
509:                        .getComponentCount() == 0);
510:            }
511:
512:            /*
513:             * Class under test for JRootPane createRootPane()
514:             */
515:            public void testCreateRootPane() {
516:                TestDialog dialog = new TestDialog();
517:                assertTrue("createRootPane() is called from the constructor",
518:                        TestDialog.createRootPaneCalled);
519:                JRootPane root = dialog.createRootPane();
520:                assertTrue("createRootPane() cannot return null", root != null);
521:            }
522:
523:            /*
524:             * Class under test for
525:             *     void setJMenuBar(JMenuBar)
526:             *     JMenuBar getJMenuBar()
527:             */
528:            public void testSetGetJMenuBarJMenuBar() {
529:                assertNull(dialog.getJMenuBar());
530:                JMenuBar menuBar = new JMenuBar();
531:                dialog.setJMenuBar(menuBar);
532:                assertTrue(dialog.getJMenuBar() == menuBar);
533:                dialog.setJMenuBar(null);
534:                assertNull(dialog.getJMenuBar());
535:            }
536:
537:            /*
538:             * Class under test for
539:             *     void setLayeredPane(JLayeredPane)
540:             *     JLayeredPane getLayeredPane()
541:             */
542:            public void testSetGetLayeredPane() {
543:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
544:                dialog.addPropertyChangeListener("layeredPane", listener);
545:                JLayeredPane pane = new JLayeredPane();
546:                dialog.setLayeredPane(pane);
547:                assertTrue(dialog.getLayeredPane() == pane);
548:                assertFalse("layeredPane is not a bound property", listener.ok);
549:                // test throwing exception if the parameter is null
550:                boolean ok = false;
551:                try {
552:                    dialog.setLayeredPane(null);
553:                } catch (IllegalComponentStateException e) {
554:                    ok = true;
555:                } finally {
556:                    assertTrue(ok);
557:                }
558:                // layeredPane cannot be null, even after setLayeredPane(null)
559:                assertTrue(dialog.getLayeredPane() != null);
560:                // setLayeredPane() method is not called by the constructor
561:                // (seems that there is an error in docs)
562:            }
563:
564:            /*
565:             * Class under test for AccessibleContext getAccessibleContext()
566:             */
567:            public void testGetAccessibleContext() {
568:                AccessibleContext c = dialog.getAccessibleContext();
569:                assertTrue("class is ok",
570:                        c instanceof  JDialog.AccessibleJDialog);
571:                assertTrue("AccessibleRole is ok",
572:                        c.getAccessibleRole() == AccessibleRole.DIALOG);
573:                assertNull("AccessibleDescription is ok", c
574:                        .getAccessibleDescription());
575:                assertTrue("AccessibleChildrenCount == 1", c
576:                        .getAccessibleChildrenCount() == 1);
577:                // test getAccessibleName()
578:                assertNull("AccessibleName is ok", c.getAccessibleName());
579:                dialog.setTitle("aa");
580:                assertTrue("AccessibleName is ok",
581:                        c.getAccessibleName() == "aa");
582:                // test getAccessibleStateSet()
583:                AccessibleState[] states = c.getAccessibleStateSet().toArray();
584:                assertTrue("more than 2 states", states.length > 2);
585:                dialog.setVisible(true);
586:                states = c.getAccessibleStateSet().toArray();
587:                assertTrue("more than 4 states", states.length > 4);
588:            }
589:
590:            /*
591:             * Class under test for String paramString()
592:             */
593:            public void testParamString() {
594:                TestDialog dialog = new TestDialog();
595:                assertTrue("paramString() cannot return null", dialog
596:                        .paramString() != null);
597:            }
598:
599:            /*
600:             * Class under test for void processWindowEvent(WindowEvent)
601:             */
602:            public void testProcessWindowEvent() {
603:                TestDialog dialog = new TestDialog();
604:                dialog.setVisible(true);
605:                WindowEvent e = new WindowEvent(dialog,
606:                        WindowEvent.WINDOW_CLOSING);
607:                // test DO_NOTHING_ON_CLOSE
608:                dialog
609:                        .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
610:                dialog.disposeCalled = false;
611:                dialog.processWindowEvent(e);
612:                assertFalse("didn't call dispose()", dialog.disposeCalled);
613:                assertTrue("is visible", dialog.isVisible());
614:                // test HIDE_ON_CLOSE
615:                dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
616:                dialog.disposeCalled = false;
617:                dialog.processWindowEvent(e);
618:                assertFalse("didn't call dispose()", dialog.disposeCalled);
619:                assertFalse("is not visible", dialog.isVisible());
620:                // test DISPOSE_ON_CLOSE
621:                dialog
622:                        .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
623:                dialog.disposeCalled = false;
624:                dialog.setVisible(true);
625:                dialog.processWindowEvent(e);
626:                assertTrue("called dispose()", dialog.disposeCalled);
627:                assertFalse("is not visible", dialog.isVisible());
628:            }
629:
630:            /*
631:             * Class under test for void setLayout(LayoutManager)
632:             */
633:            public void testSetLayout() {
634:                TestDialog dialog = new TestDialog();
635:                LayoutManager contentLayout = dialog.getContentPane()
636:                        .getLayout();
637:                LayoutManager dialogLayout = dialog.getLayout();
638:                // rootPaneCheckingEnabled is true, no exception since 1.5
639:                dialog.setRootPaneCheckingEnabled(true);
640:                boolean ok = false;
641:                try {
642:                    dialog.setLayout(new FlowLayout());
643:                } catch (Error e) {
644:                    ok = true;
645:                } finally {
646:                    assertFalse("no exception since 1.5", ok);
647:                    assertTrue("contentPane layout is changed", dialog
648:                            .getContentPane().getLayout() != contentLayout);
649:                    assertTrue("Dialog layout shouldn't be changed", dialog
650:                            .getLayout() == dialogLayout);
651:                    dialog.getContentPane().setLayout(contentLayout);
652:                }
653:                // rootPaneCheckingEnabled is false
654:                dialog.setRootPaneCheckingEnabled(false);
655:                ok = false;
656:                try {
657:                    dialog.setLayout(new FlowLayout());
658:                } catch (Error e) {
659:                    ok = true;
660:                } finally {
661:                    assertFalse("no exception", ok);
662:                    assertTrue(
663:                            "contentPane layout shouldn't be changed",
664:                            dialog.getContentPane().getLayout() == contentLayout);
665:                    assertTrue("Dialog layout is changed",
666:                            dialog.getLayout() != dialogLayout);
667:                }
668:            }
669:
670:            /*
671:             * Class under test for void update(Graphics)
672:             */
673:            public void testUpdate() {
674:                // Note: painting code, cannot test
675:            }
676:
677:            /*
678:             * Class under test for
679:             *     void setContentPane(Container)
680:             *     Container getContentPane()
681:             */
682:            public void testSetGetContentPane() {
683:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
684:                dialog.addPropertyChangeListener("contentPane", listener);
685:                JPanel pane = new JPanel();
686:                dialog.setContentPane(pane);
687:                assertTrue(dialog.getContentPane() == pane);
688:                assertFalse("contentPane is not a bound property", listener.ok);
689:                // test throwing exception if the parameter is null
690:                boolean ok = false;
691:                try {
692:                    dialog.setContentPane(null);
693:                } catch (IllegalComponentStateException e) {
694:                    ok = true;
695:                } finally {
696:                    assertTrue(ok);
697:                }
698:                // contentPane cannot be null, even after setContentPane(null)
699:                assertTrue(dialog.getContentPane() != null);
700:                // setContentPane() method is not called by the constructor
701:                // (seems that there is an error in docs)
702:            }
703:
704:            /*
705:             * Class under test for
706:             *     void setGlassPane(Component)
707:             *     Component getGlassPane()
708:             */
709:            public void testSetGetGlassPane() {
710:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
711:                dialog.addPropertyChangeListener("glassPane", listener);
712:                JPanel pane = new JPanel();
713:                dialog.setGlassPane(pane);
714:                assertTrue(dialog.getGlassPane() == pane);
715:                assertFalse("glassPane is not a bound property", listener.ok);
716:                // test throwing exception if the parameter is null
717:                boolean ok = false;
718:                try {
719:                    dialog.setGlassPane(null);
720:                } catch (NullPointerException e) {
721:                    ok = true;
722:                } finally {
723:                    assertTrue(ok);
724:                }
725:                // glassPane cannot be null, even after setGlassPane(null)
726:                assertTrue(dialog.getGlassPane() != null);
727:                // setGlassPane() method is not called by the constructor
728:                // (seems that there is an error in docs)
729:            }
730:
731:            /*
732:             * Class under test for void remove(Component)
733:             */
734:            public void testRemove() {
735:                JComponent comp = new JPanel();
736:                dialog.getContentPane().add(comp);
737:                assertTrue("added to contentPane", dialog.isAncestorOf(comp));
738:                dialog.remove(comp);
739:                assertFalse("removed from contentPane", dialog
740:                        .isAncestorOf(comp));
741:                ((JPanel) dialog.getGlassPane()).add(comp);
742:                dialog.remove(comp);
743:                assertTrue("not removed from glassPane", dialog
744:                        .isAncestorOf(comp));
745:                // test removing directly from the container
746:                dialog.setRootPaneCheckingEnabled(false);
747:                dialog.add(comp, BorderLayout.EAST);
748:                assertTrue("added", comp.getParent() == dialog);
749:                dialog.remove(comp);
750:                assertTrue("not removed", comp.getParent() == dialog);
751:                // test removing null
752:                //        boolean ok = false;
753:                //        try {
754:                //            dialog.remove((Component)null);
755:                //        } catch (NullPointerException e) {
756:                //            ok = true;
757:                //        } finally {
758:                //            assertTrue("exception", ok);
759:                //        }
760:                // test removing rootPane
761:                assertTrue(dialog.isAncestorOf(dialog.getRootPane()));
762:                dialog.remove(dialog.getRootPane());
763:                // rootPane is removed from the container
764:                assertFalse(dialog.isAncestorOf(dialog.getRootPane()));
765:                // but getRootPane() still returns it
766:                assertTrue(dialog.getRootPane() != null);
767:            }
768:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.