Source Code Cross Referenced for JInternalFrameTest.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 Vadim L. Bogdanov
0019:         * @version $Revision$
0020:         */package javax.swing;
0021:
0022:        import java.awt.BorderLayout;
0023:        import java.awt.Component;
0024:        import java.awt.Dimension;
0025:        import java.awt.FlowLayout;
0026:        import java.awt.IllegalComponentStateException;
0027:        import java.awt.KeyboardFocusManager;
0028:        import java.awt.LayoutManager;
0029:        import java.awt.Point;
0030:        import java.awt.Rectangle;
0031:        import java.beans.PropertyChangeEvent;
0032:        import java.beans.PropertyChangeListener;
0033:        import java.beans.PropertyVetoException;
0034:        import java.beans.VetoableChangeListener;
0035:        import javax.accessibility.AccessibleContext;
0036:        import javax.accessibility.AccessibleRole;
0037:        import javax.accessibility.AccessibleValue;
0038:        import javax.swing.event.InternalFrameEvent;
0039:        import javax.swing.event.InternalFrameListener;
0040:        import javax.swing.plaf.ComponentUI;
0041:        import javax.swing.plaf.basic.BasicInternalFrameUI;
0042:
0043:        @SuppressWarnings("serial")
0044:        public class JInternalFrameTest extends SwingTestCase {
0045:            /*
0046:             * This class is used to test that some methods were called.
0047:             */
0048:            static private class TestInternalFrame extends JInternalFrame {
0049:                public static boolean createRootPaneCalled = false;
0050:
0051:                public static boolean setRootPaneCalled = false;
0052:
0053:                public static boolean disposeCalled = false;
0054:
0055:                @Override
0056:                public JRootPane createRootPane() {
0057:                    createRootPaneCalled = true;
0058:                    return super .createRootPane();
0059:                }
0060:
0061:                @Override
0062:                public void setRootPane(final JRootPane root) {
0063:                    setRootPaneCalled = true;
0064:                    super .setRootPane(root);
0065:                }
0066:
0067:                public static void initStaticVars() {
0068:                    createRootPaneCalled = false;
0069:                    setRootPaneCalled = false;
0070:                    disposeCalled = false;
0071:                }
0072:
0073:                @Override
0074:                public void dispose() {
0075:                    disposeCalled = true;
0076:                    super .dispose();
0077:                }
0078:            }
0079:
0080:            /*
0081:             * This class is used to test that some property is a constrained property
0082:             */
0083:            private class MyVetoableChangeListener implements 
0084:                    VetoableChangeListener {
0085:                protected String name;
0086:
0087:                MyVetoableChangeListener(final String name) {
0088:                    this .name = name;
0089:                }
0090:
0091:                public void vetoableChange(final PropertyChangeEvent evt)
0092:                        throws PropertyVetoException {
0093:                    if (evt.getPropertyName() == name) {
0094:                        throw new PropertyVetoException("", evt);
0095:                    }
0096:                }
0097:            }
0098:
0099:            private class MyInternalFrameListener implements 
0100:                    InternalFrameListener {
0101:                public int state;
0102:
0103:                private static final int opened = 1;
0104:
0105:                private static final int closing = 2;
0106:
0107:                private static final int closed = 4;
0108:
0109:                private static final int iconified = 8;
0110:
0111:                private static final int deiconified = 16;
0112:
0113:                private static final int activated = 32;
0114:
0115:                private static final int deactivated = 64;
0116:
0117:                MyInternalFrameListener() {
0118:                    state = 0;
0119:                }
0120:
0121:                public void internalFrameOpened(final InternalFrameEvent e) {
0122:                    state |= opened;
0123:                }
0124:
0125:                public void internalFrameClosing(final InternalFrameEvent e) {
0126:                    state |= closing;
0127:                }
0128:
0129:                public void internalFrameClosed(final InternalFrameEvent e) {
0130:                    state |= closed;
0131:                }
0132:
0133:                public void internalFrameIconified(final InternalFrameEvent e) {
0134:                    state |= iconified;
0135:                }
0136:
0137:                public void internalFrameDeiconified(final InternalFrameEvent e) {
0138:                    state |= deiconified;
0139:                }
0140:
0141:                public void internalFrameActivated(final InternalFrameEvent e) {
0142:                    state |= activated;
0143:                }
0144:
0145:                public void internalFrameDeactivated(final InternalFrameEvent e) {
0146:                    state |= deactivated;
0147:                }
0148:
0149:                public boolean openedFired() {
0150:                    return (state & opened) != 0;
0151:                }
0152:
0153:                public boolean closingFired() {
0154:                    return (state & closing) != 0;
0155:                }
0156:
0157:                public boolean closedFired() {
0158:                    return (state & closed) != 0;
0159:                }
0160:
0161:                public boolean iconifiedFired() {
0162:                    return (state & iconified) != 0;
0163:                }
0164:
0165:                public boolean deiconifiedFired() {
0166:                    return (state & deiconified) != 0;
0167:                }
0168:
0169:                public boolean activatedFired() {
0170:                    return (state & activated) != 0;
0171:                }
0172:
0173:                public boolean deactivatedFired() {
0174:                    return (state & deactivated) != 0;
0175:                }
0176:            }
0177:
0178:            /*
0179:             * This class is used to test that some property is (or is not) a bound property
0180:             */
0181:            private class MyPropertyChangeListener implements 
0182:                    PropertyChangeListener {
0183:                public boolean ok;
0184:
0185:                MyPropertyChangeListener() {
0186:                    ok = false;
0187:                }
0188:
0189:                public void propertyChange(final PropertyChangeEvent e) {
0190:                    ok = true;
0191:                }
0192:            }
0193:
0194:            private JInternalFrame frame;
0195:
0196:            // is used in tests where frame.isShowing() must be true
0197:            private JFrame rootFrame;
0198:
0199:            /*
0200:             * @see TestCase#setUp()
0201:             */
0202:            @Override
0203:            protected void setUp() throws Exception {
0204:                super .setUp();
0205:                frame = new JInternalFrame();
0206:                TestInternalFrame.initStaticVars();
0207:            }
0208:
0209:            /*
0210:             * @see TestCase#tearDown()
0211:             */
0212:            @Override
0213:            protected void tearDown() throws Exception {
0214:                if (rootFrame != null) {
0215:                    rootFrame.dispose();
0216:                    rootFrame = null;
0217:                }
0218:                super .tearDown();
0219:            }
0220:
0221:            /**
0222:             * Constructor for JInternalFrameTest.
0223:             * @param name
0224:             */
0225:            public JInternalFrameTest(final String name) {
0226:                super (name);
0227:            }
0228:
0229:            /*
0230:             * Class under test for void reshape(int, int, int, int).
0231:             * Actually, reshape() seems to be obsolete, we'll test setBounds()
0232:             * instead.
0233:             */
0234:            public void testReshape() {
0235:                final Point location = new Point(20, 21);
0236:                final int width = 22;
0237:                final int height = 23;
0238:                frame.setBounds(location.x, location.y, width, height);
0239:                assertTrue("location is set", frame.getLocation().equals(
0240:                        location));
0241:                assertTrue("width is set", frame.getWidth() == width);
0242:                assertTrue("height is set", frame.getHeight() == height);
0243:                // Note: could test that the component was re-layouted
0244:            }
0245:
0246:            /*
0247:             * Class under test for void updateUI()
0248:             */
0249:            public void testUpdateUI() {
0250:                frame.updateUI();
0251:                ComponentUI ui1 = frame.getUI();
0252:                ComponentUI ui2 = UIManager.getUI(frame);
0253:                // at least names of classes must be the same
0254:                assertEquals(ui2.getClass().getName(), ui1.getClass().getName());
0255:            }
0256:
0257:            /*
0258:             * Checks correctness of the internal frame after constructor.
0259:             */
0260:            protected void checkJInternalFrameCorrectness(final String title,
0261:                    final boolean resizable, final boolean closable,
0262:                    final boolean maximizable, final boolean iconifiable) {
0263:                assertTrue("title is set", frame.getTitle() == title);
0264:                assertTrue("resizable is set", frame.isResizable() == resizable);
0265:                assertTrue("closable is set", frame.isClosable() == closable);
0266:                assertTrue("maximizable is set",
0267:                        frame.isMaximizable() == maximizable);
0268:                assertTrue("iconifiable is set",
0269:                        frame.isIconifiable() == iconifiable);
0270:                assertFalse("is visible by default", frame.isVisible());
0271:                assertTrue("rootPane != null", frame.getRootPane() != null);
0272:                assertTrue("locale is set", frame.getLocale() == JComponent
0273:                        .getDefaultLocale());
0274:                assertTrue(
0275:                        "",
0276:                        frame.getRootPane().getWindowDecorationStyle() == JRootPane.NONE);
0277:                assertTrue("", frame.getBackground() == frame.getContentPane()
0278:                        .getBackground());
0279:                assertTrue("ui != null", frame.getUI() != null);
0280:                assertTrue("is focus cycle root", frame.isFocusCycleRoot());
0281:                assertTrue("glassPane is visible", frame.getGlassPane()
0282:                        .isVisible());
0283:                // test that defaultFocusTraversalPolicy is set
0284:                assertTrue("focusTraversalPolicy is set", frame
0285:                        .isFocusTraversalPolicySet());
0286:                assertTrue("focusTraversalPolicy is set correctly", frame
0287:                        .getFocusTraversalPolicy() == KeyboardFocusManager
0288:                        .getCurrentKeyboardFocusManager()
0289:                        .getDefaultFocusTraversalPolicy());
0290:                assertTrue(frame.isFocusCycleRoot());
0291:                assertFalse(frame.isFocusTraversalPolicyProvider());
0292:            }
0293:
0294:            /*
0295:             * Class under test for void JInternalFrame()
0296:             */
0297:            public void testJInternalFrame() {
0298:                frame = new JInternalFrame();
0299:                checkJInternalFrameCorrectness("", false, false, false, false);
0300:            }
0301:
0302:            /*
0303:             * Class under test for void doDefaultCloseAction()
0304:             */
0305:            public void testDoDefaultCloseAction() {
0306:                TestInternalFrame frame = new TestInternalFrame();
0307:                MyInternalFrameListener listener = new MyInternalFrameListener();
0308:                frame.addInternalFrameListener(listener);
0309:                frame.setVisible(true);
0310:                // test DO_NOTHING_ON_CLOSE operation
0311:                TestInternalFrame.initStaticVars();
0312:                listener.state = 0;
0313:                frame
0314:                        .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
0315:                frame.doDefaultCloseAction();
0316:                assertTrue("INTERNAL_FRAME_CLOSING was fired", listener
0317:                        .closingFired());
0318:                assertFalse("dispose() was not called",
0319:                        TestInternalFrame.disposeCalled);
0320:                assertTrue("setVisible(false) was not called", frame
0321:                        .isVisible());
0322:                // test DISPOSE_ON_CLOSE operation
0323:                TestInternalFrame.initStaticVars();
0324:                listener.state = 0;
0325:                frame
0326:                        .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
0327:                frame.doDefaultCloseAction();
0328:                assertTrue("dispose() was called",
0329:                        TestInternalFrame.disposeCalled);
0330:                assertTrue("INTERNAL_FRAME_CLOSING was fired", listener
0331:                        .closingFired());
0332:                // test HIDE_ON_CLOSE operation
0333:                TestInternalFrame.initStaticVars();
0334:                listener.state = 0;
0335:                frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
0336:                frame.doDefaultCloseAction();
0337:                assertFalse("dispose() was not called",
0338:                        TestInternalFrame.disposeCalled);
0339:                assertFalse("setVisible(false) was called", frame.isVisible());
0340:                assertTrue("INTERNAL_FRAME_CLOSING was fired", listener
0341:                        .closingFired());
0342:            }
0343:
0344:            /*
0345:             * Class under test for void pack()
0346:             */
0347:            public void testPack() {
0348:                final JComponent comp1 = new JPanel();
0349:                final JComponent comp2 = new JPanel();
0350:                comp2.setPreferredSize(new Dimension(60, 20));
0351:                final Component comp3 = new JPanel();
0352:                frame.getContentPane().add(comp1, BorderLayout.NORTH);
0353:                frame.getContentPane().add(comp2, BorderLayout.SOUTH);
0354:                frame.getContentPane().add(comp3, BorderLayout.CENTER);
0355:                createAndShowRootFrame();
0356:                frame.pack();
0357:                assertTrue("size is set to preferred size", frame.getRootPane()
0358:                        .getSize().equals(
0359:                                frame.getRootPane().getPreferredSize()));
0360:            }
0361:
0362:            /*
0363:             * Class under test for void moveToBack()
0364:             */
0365:            public void testMoveToBack() {
0366:                // test without JDesktopPane set
0367:                frame.moveToBack();
0368:                // test with JDesktopPane set
0369:                JDesktopPane desktop = new JDesktopPane();
0370:                desktop.add(frame);
0371:                desktop.add(new JInternalFrame());
0372:                desktop.add(new JInternalFrame());
0373:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0374:                frame.moveToBack();
0375:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0376:                // test with different layer
0377:                frame.setLayer(1);
0378:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0379:                frame.moveToBack();
0380:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0381:            }
0382:
0383:            /*
0384:             * Class under test for void moveToFront()
0385:             */
0386:            public void testMoveToFront() {
0387:                // test without JDesktopPane set
0388:                frame.moveToFront();
0389:                // test with JDesktopPane set
0390:                //JDesktopPane desktop = new JDesktopPane();
0391:                JLayeredPane desktop = new JLayeredPane();
0392:                desktop.add(new JInternalFrame());
0393:                desktop.add(new JInternalFrame());
0394:                desktop.add(frame);
0395:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0396:                frame.moveToFront();
0397:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0398:                // test with different layer
0399:                frame.setLayer(-1);
0400:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0401:                frame.moveToFront();
0402:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0403:            }
0404:
0405:            /*
0406:             * Class under test for void toBack()
0407:             */
0408:            public void testToBack() {
0409:                // test without JDesktopPane set
0410:                frame.toBack();
0411:                // test with JDesktopPane set
0412:                JDesktopPane desktop = new JDesktopPane();
0413:                desktop.add(frame);
0414:                desktop.add(new JInternalFrame());
0415:                desktop.add(new JInternalFrame());
0416:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0417:                frame.toBack();
0418:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0419:                // test with different layer
0420:                frame.setLayer(1);
0421:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0422:                frame.toBack();
0423:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0424:            }
0425:
0426:            /*
0427:             * Class under test for void toFront()
0428:             */
0429:            public void testToFront() {
0430:                // test without JDesktopPane set
0431:                frame.toFront();
0432:                // test with JDesktopPane set
0433:                JLayeredPane desktop = new JLayeredPane();
0434:                desktop.add(new JInternalFrame());
0435:                desktop.add(new JInternalFrame());
0436:                desktop.add(frame);
0437:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0438:                frame.toFront();
0439:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0440:                // test with different layer
0441:                frame.setLayer(-1);
0442:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0443:                frame.toFront();
0444:                assertTrue("frame index is 2", desktop.getIndexOf(frame) == 2);
0445:            }
0446:
0447:            /*
0448:             * Class under test for void fireInternalFrameEvent(int)
0449:             */
0450:            public void testFireInternalFrameEvent() {
0451:                TestInternalFrame frame = new TestInternalFrame();
0452:                MyInternalFrameListener l = new MyInternalFrameListener();
0453:                frame.addInternalFrameListener(l);
0454:                l.state = 0;
0455:                frame
0456:                        .fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_OPENED);
0457:                assertTrue("INTERNAL_FRAME_OPENED was fired", l.openedFired());
0458:                l.state = 0;
0459:                frame
0460:                        .fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSING);
0461:                assertTrue("INTERNAL_FRAME_CLOSING was fired", l.closingFired());
0462:                l.state = 0;
0463:                frame
0464:                        .fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_CLOSED);
0465:                assertTrue("INTERNAL_FRAME_CLOSED was fired", l.closedFired());
0466:                l.state = 0;
0467:                frame
0468:                        .fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ICONIFIED);
0469:                assertTrue("INTERNAL_FRAME_ICONIFIED was fired", l
0470:                        .iconifiedFired());
0471:                l.state = 0;
0472:                frame
0473:                        .fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED);
0474:                assertTrue("INTERNAL_FRAME_DEICONIFIED was fired", l
0475:                        .deiconifiedFired());
0476:                l.state = 0;
0477:                frame
0478:                        .fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_ACTIVATED);
0479:                assertTrue("INTERNAL_FRAME_ACTIVATED was fired", l
0480:                        .activatedFired());
0481:                l.state = 0;
0482:                frame
0483:                        .fireInternalFrameEvent(InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED);
0484:                assertTrue("INTERNAL_FRAME_DEACTIVATED was fired", l
0485:                        .deactivatedFired());
0486:                l.state = 0;
0487:                frame.fireInternalFrameEvent(101); // test invalid value
0488:                assertTrue("nothing happens", l.state == 0);
0489:            }
0490:
0491:            /*
0492:             * Class under test for
0493:             *     void setDefaultCloseOperation(int operation)
0494:             *     int getDefaultCloseOperation()
0495:             */
0496:            public void testSetGetDefaultCloseOperation() {
0497:                // default value is JInternalFrame.DISPOSE_ON_CLOSE
0498:                assertEquals(WindowConstants.DISPOSE_ON_CLOSE, frame
0499:                        .getDefaultCloseOperation());
0500:                // test setting valid value
0501:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
0502:                frame.addPropertyChangeListener("defaultCloseOperation",
0503:                        listener);
0504:                frame
0505:                        .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
0506:                assertEquals(WindowConstants.DO_NOTHING_ON_CLOSE, frame
0507:                        .getDefaultCloseOperation());
0508:                assertFalse("defaultCloseOperation is not a bound property",
0509:                        listener.ok);
0510:                // test setting invalid value
0511:                boolean ok = false;
0512:                try {
0513:                    frame.setDefaultCloseOperation(101); // invalid value
0514:                } catch (IllegalArgumentException e) {
0515:                    ok = true;
0516:                } finally {
0517:                    assertFalse("no exception", ok);
0518:                    assertTrue("Invalid value is set", frame
0519:                            .getDefaultCloseOperation() == 101);
0520:                }
0521:            }
0522:
0523:            /*
0524:             * Class under test for
0525:             *     void setLayer(int)
0526:             *     int getLayer()
0527:             */
0528:            public void testSetGetLayer() {
0529:                assertTrue("default level is 0", frame.getLayer() == 0);
0530:                // test setLayer() without JDesktopPane set
0531:                frame.setLayer(1);
0532:                assertTrue("layer is set", frame.getLayer() == 1);
0533:                // tes setLayer with JLayeredPane set
0534:                JLayeredPane desktop = new JLayeredPane();
0535:                desktop.add(frame);
0536:                desktop.add(new JInternalFrame());
0537:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0538:                frame.setLayer(-1);
0539:                assertTrue("frame index is 1", desktop.getIndexOf(frame) == 1);
0540:            }
0541:
0542:            /*
0543:             * Class under test for void setLayer(Integer)
0544:             */
0545:            public void testSetLayerInteger() {
0546:                // test setLayer() without JDesktopPane set
0547:                frame.setLayer(new Integer(1));
0548:                assertTrue("layer is set", frame.getLayer() == 1);
0549:                // tes setLayer with JDesktopPane set
0550:                JDesktopPane desktop = new JDesktopPane();
0551:                desktop.add(frame);
0552:                desktop.add(new JInternalFrame());
0553:                assertTrue("frame index is 0", desktop.getIndexOf(frame) == 0);
0554:                frame.setLayer(new Integer(-1));
0555:                assertTrue("frame index is 1", desktop.getIndexOf(frame) == 1);
0556:            }
0557:
0558:            /*
0559:             * Class under test for
0560:             *     void setClosable(boolean)
0561:             *     boolean isClosable()
0562:             */
0563:            public void testSetIsClosable() {
0564:                assertFalse("closable is false by default", frame.isClosable());
0565:                frame.setClosable(true);
0566:                assertTrue("closable is set", frame.isClosable());
0567:            }
0568:
0569:            /*
0570:             * Class under test for
0571:             *     void setClosed(boolean)
0572:             *     boolean isClosed()
0573:             */
0574:            public void testSetIsClosed() {
0575:                MyInternalFrameListener frameListener = new MyInternalFrameListener();
0576:                frame.addInternalFrameListener(frameListener);
0577:                MyPropertyChangeListener l = new MyPropertyChangeListener();
0578:                frame.addPropertyChangeListener(
0579:                        JInternalFrame.IS_CLOSED_PROPERTY, l);
0580:                //try {
0581:                //    SwingUtilities.invokeAndWait(new Runnable() {
0582:                //        public void run() {
0583:                createAndShowRootFrame();
0584:                //        }
0585:                //    });
0586:                //} catch (Exception e) {
0587:                //    assertFalse("exception", true);
0588:                //}
0589:                assertFalse("false by default", frame.isClosed());
0590:                // test that this is a constrained property
0591:                boolean thrown = false;
0592:                l.ok = false;
0593:                MyVetoableChangeListener vetoableListener = new MyVetoableChangeListener(
0594:                        JInternalFrame.IS_CLOSED_PROPERTY);
0595:                frame.addVetoableChangeListener(vetoableListener);
0596:                try {
0597:                    frame.setSelected(true);
0598:                    frameListener.state = 0;
0599:                    frame.setClosed(true);
0600:                } catch (PropertyVetoException e) {
0601:                    thrown = true;
0602:                } finally {
0603:                    assertTrue("exception is thrown", thrown);
0604:                    assertFalse("isClosed is not set", frame.isClosed());
0605:                    assertTrue("CLOSING fired", frameListener.closingFired());
0606:                    assertFalse("CLOSED not fired", frameListener.closedFired());
0607:                    assertTrue("frame is visible", frame.isVisible());
0608:                    assertTrue("frame is selected", frame.isSelected());
0609:                    assertFalse("property change was not fired", l.ok);
0610:                    assertTrue("not removed", rootFrame.isAncestorOf(frame));
0611:                }
0612:                // test that this a a bound property
0613:                thrown = false;
0614:                l.ok = false;
0615:                frame.removeVetoableChangeListener(vetoableListener);
0616:                try {
0617:                    frameListener.state = 0;
0618:                    frame.setClosed(true);
0619:                } catch (PropertyVetoException e) {
0620:                    thrown = true;
0621:                } finally {
0622:                    assertFalse("exception is no thrown", thrown);
0623:                    assertTrue("isClosed is set", frame.isClosed());
0624:                    assertTrue("CLOSING fired", frameListener.closingFired());
0625:                    assertTrue("CLOSED fired", frameListener.closedFired());
0626:                    assertFalse("frame is visible", frame.isVisible());
0627:                    assertFalse("frame is selected", frame.isSelected());
0628:                    assertTrue("property change was not fired", l.ok);
0629:                    assertFalse("removed", rootFrame.isAncestorOf(frame));
0630:                }
0631:                // test setting to try second time
0632:                thrown = false;
0633:                l.ok = false;
0634:                try {
0635:                    frameListener.state = 0;
0636:                    frame.setClosed(true);
0637:                } catch (PropertyVetoException e) {
0638:                    thrown = true;
0639:                } finally {
0640:                    assertFalse("exception is no thrown", thrown);
0641:                    assertFalse("CLOSING not fired", frameListener
0642:                            .closingFired());
0643:                    assertFalse("CLOSED not fired", frameListener.closedFired());
0644:                }
0645:            }
0646:
0647:            /*
0648:             * Class under test for
0649:             *     void setIcon(boolean)
0650:             *     boolean isIcon()
0651:             */
0652:            public void testSetIsIcon() {
0653:                JDesktopPane desktop = new JDesktopPane();
0654:                desktop.add(frame);
0655:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
0656:                frame.addPropertyChangeListener(
0657:                        JInternalFrame.IS_ICON_PROPERTY, listener);
0658:                MyInternalFrameListener frameListener = new MyInternalFrameListener();
0659:                frame.addInternalFrameListener(frameListener);
0660:                boolean thrown;
0661:                assertFalse("isIcon is false by default", frame.isIcon());
0662:                // test correct set to true
0663:                thrown = false;
0664:                frameListener.state = 0;
0665:                try {
0666:                    frame.setIcon(true);
0667:                } catch (PropertyVetoException e) {
0668:                    thrown = true;
0669:                } finally {
0670:                    assertFalse("exception is not thrown", thrown);
0671:                    assertTrue("isIcon is set", frame.isIcon());
0672:                    assertTrue("isIcon is a bound property", listener.ok);
0673:                    assertTrue("INTERNAL_FRAME_ICONIFIED event", frameListener
0674:                            .iconifiedFired());
0675:                }
0676:                // test correct set to false
0677:                thrown = false;
0678:                frameListener.state = 0;
0679:                try {
0680:                    frame.setIcon(false);
0681:                } catch (PropertyVetoException e) {
0682:                    thrown = true;
0683:                } finally {
0684:                    assertFalse("exception is not thrown", thrown);
0685:                    assertFalse("isIcon is set", frame.isIcon());
0686:                    assertTrue("INTERNAL_FRAME_DEICONIFIED event",
0687:                            frameListener.deiconifiedFired());
0688:                }
0689:                // test set to false when it is false already
0690:                thrown = false;
0691:                frameListener.state = 0;
0692:                try {
0693:                    frame.setIcon(false);
0694:                } catch (PropertyVetoException e) {
0695:                    thrown = true;
0696:                } finally {
0697:                    assertFalse("exception is not thrown", thrown);
0698:                    assertFalse("isIcon is set", frame.isIcon());
0699:                    assertTrue("no events", frameListener.state == 0);
0700:                }
0701:                // test that this is a constrained property
0702:                thrown = false;
0703:                frameListener.state = 0;
0704:                frame.addVetoableChangeListener(new MyVetoableChangeListener(
0705:                        JInternalFrame.IS_ICON_PROPERTY));
0706:                try {
0707:                    frame.setIcon(true);
0708:                } catch (PropertyVetoException e) {
0709:                    thrown = true;
0710:                } finally {
0711:                    assertTrue("exception is thrown", thrown);
0712:                    assertFalse("isIcon is not set", frame.isIcon());
0713:                    assertTrue("no events", frameListener.state == 0);
0714:                }
0715:            }
0716:
0717:            /*
0718:             * Class under test for
0719:             *     void setIconifiable(boolean)
0720:             *     boolean isIconifiable()
0721:             */
0722:            public void testSetIsIconifiable() {
0723:                assertFalse("iconable is false by default", frame
0724:                        .isIconifiable());
0725:                frame.setIconifiable(true);
0726:                assertTrue("iconable is set", frame.isIconifiable());
0727:            }
0728:
0729:            /*
0730:             * Class under test for
0731:             *     void setMaximizable(boolean)
0732:             *     boolean isMaximizable()
0733:             */
0734:            public void testSetIsMaximizable() {
0735:                assertFalse("maximizable is false by default", frame
0736:                        .isMaximizable());
0737:                frame.setMaximizable(true);
0738:                assertTrue("maximizable is set", frame.isMaximizable());
0739:            }
0740:
0741:            /*
0742:             * Class under test for
0743:             *     void setMaximum(boolean)
0744:             *     boolean isMaximum()
0745:             */
0746:            public void testSetIsMaximum() {
0747:                JDesktopPane desktop = new JDesktopPane();
0748:                desktop.add(frame);
0749:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
0750:                frame.addPropertyChangeListener(
0751:                        JInternalFrame.IS_MAXIMUM_PROPERTY, listener);
0752:                boolean thrown;
0753:                assertFalse("isMaximum is false by default", frame.isMaximum());
0754:                // test correct set to true
0755:                thrown = false;
0756:                try {
0757:                    frame.setMaximum(true);
0758:                } catch (PropertyVetoException e) {
0759:                    thrown = true;
0760:                } finally {
0761:                    assertFalse("exception is not thrown", thrown);
0762:                    assertTrue("isMaximum is set", frame.isMaximum());
0763:                    assertTrue("isMaximum is a bound property", listener.ok);
0764:                }
0765:                // test correct set to false
0766:                thrown = false;
0767:                try {
0768:                    frame.setMaximum(false);
0769:                } catch (PropertyVetoException e) {
0770:                    thrown = true;
0771:                } finally {
0772:                    assertFalse("exception is not thrown", thrown);
0773:                    assertFalse("isMaximum is set", frame.isMaximum());
0774:                }
0775:                // test set to false when it is false already
0776:                thrown = false;
0777:                try {
0778:                    frame.setMaximum(false);
0779:                } catch (PropertyVetoException e) {
0780:                    thrown = true;
0781:                } finally {
0782:                    assertFalse("exception is not thrown", thrown);
0783:                    assertFalse("isMaximum is set", frame.isMaximum());
0784:                }
0785:                // test that this is a constrained property
0786:                thrown = false;
0787:                frame.addVetoableChangeListener(new MyVetoableChangeListener(
0788:                        JInternalFrame.IS_MAXIMUM_PROPERTY));
0789:                try {
0790:                    frame.setMaximum(true);
0791:                } catch (PropertyVetoException e) {
0792:                    thrown = true;
0793:                } finally {
0794:                    assertTrue("exception is thrown", thrown);
0795:                    assertFalse("isIcon is not set", frame.isMaximum());
0796:                }
0797:            }
0798:
0799:            /*
0800:             * Class under test for
0801:             *     void setResizable(boolean)
0802:             *     boolean isResizable()
0803:             */
0804:            public void testSetIsResizable() {
0805:                assertFalse("resizable is false by default", frame
0806:                        .isResizable());
0807:                frame.setResizable(true);
0808:                assertTrue("resizable is set", frame.isResizable());
0809:            }
0810:
0811:            /*
0812:             * Class under test for
0813:             *     void setRootPaneCheckingEnabled(boolean enabled)
0814:             *     boolean isRootPaneCheckingEnabled()
0815:             */
0816:            public void testSetIsRootPaneCheckingEnabled() {
0817:                TestInternalFrame frame = new TestInternalFrame();
0818:                assertTrue("rootPaneCheckingEnabled is true by default", frame
0819:                        .isRootPaneCheckingEnabled());
0820:                frame.setRootPaneCheckingEnabled(false);
0821:                assertFalse("rootPaneCheckingEnabled is set to false", frame
0822:                        .isRootPaneCheckingEnabled());
0823:            }
0824:
0825:            /*
0826:             * Class under test for
0827:             *     void setSelected(boolean)
0828:             *     boolean isSelected()
0829:             */
0830:            public void testSetIsSelected() {
0831:                createAndShowRootFrame();
0832:                rootFrame.getContentPane().add(new JInternalFrame()); // to make 'frame' not selectable by default
0833:                //rootFrame.getContentPane().add(frame);
0834:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
0835:                frame.addPropertyChangeListener(
0836:                        JInternalFrame.IS_SELECTED_PROPERTY, listener);
0837:                MyInternalFrameListener frameListener = new MyInternalFrameListener();
0838:                frame.addInternalFrameListener(frameListener);
0839:                boolean thrown;
0840:                assertFalse("isSelected is false by default", frame
0841:                        .isSelected());
0842:                // test set to true when the internal frame is invisible
0843:                thrown = false;
0844:                frame.setVisible(false);
0845:                try {
0846:                    frame.setSelected(true);
0847:                } catch (PropertyVetoException e) {
0848:                    thrown = true;
0849:                } finally {
0850:                    assertFalse("exception is not thrown", thrown);
0851:                    assertFalse("isSelected is not set", frame.isSelected());
0852:                }
0853:                // test correct set to true
0854:                thrown = false;
0855:                frame.setVisible(true);
0856:                try {
0857:                    frame.setSelected(false);
0858:                } catch (PropertyVetoException e) {
0859:                }
0860:                frameListener.state = 0;
0861:                listener.ok = false;
0862:                assertFalse("isSelected is false", frame.isSelected());
0863:                try {
0864:                    frame.setSelected(true);
0865:                } catch (PropertyVetoException e) {
0866:                    thrown = true;
0867:                } finally {
0868:                    assertFalse("exception is not thrown", thrown);
0869:                    assertTrue("isSelected is set", frame.isSelected());
0870:                    assertTrue("isSelected is a bound property", listener.ok);
0871:                    assertTrue("event fired", frameListener.activatedFired());
0872:                    assertFalse("glassPane is invisible", frame.getGlassPane()
0873:                            .isVisible());
0874:                }
0875:                // test set to false when the internal frame is invisible
0876:                thrown = false;
0877:                frame.setVisible(false);
0878:                assertTrue("isSelected is true", frame.isSelected());
0879:                try {
0880:                    frame.setSelected(false);
0881:                } catch (PropertyVetoException e) {
0882:                    thrown = true;
0883:                } finally {
0884:                    assertFalse("exception is not thrown", thrown);
0885:                    assertFalse("isSelected is set", frame.isSelected());
0886:                }
0887:                // test correct set to false
0888:                thrown = false;
0889:                frame.setVisible(true);
0890:                assertTrue("isSelected is true", frame.isSelected());
0891:                frameListener.state = 0;
0892:                try {
0893:                    frame.setSelected(false);
0894:                } catch (PropertyVetoException e) {
0895:                    thrown = true;
0896:                } finally {
0897:                    assertFalse("exception is not thrown", thrown);
0898:                    assertFalse("isSelected is set", frame.isSelected());
0899:                    assertTrue("isSelected is a bound property", listener.ok);
0900:                    assertTrue("event fired", frameListener.deactivatedFired());
0901:                    assertTrue("glassPane is visible", frame.getGlassPane()
0902:                            .isVisible());
0903:                }
0904:                // test set to false when it is false already
0905:                thrown = false;
0906:                try {
0907:                    frame.setSelected(false);
0908:                } catch (PropertyVetoException e) {
0909:                    thrown = true;
0910:                } finally {
0911:                    assertFalse("exception is not thrown", thrown);
0912:                    assertFalse("isSelected is set", frame.isSelected());
0913:                }
0914:                // test that this is a constrained property
0915:                thrown = false;
0916:                MyVetoableChangeListener vetoableListener = new MyVetoableChangeListener(
0917:                        JInternalFrame.IS_SELECTED_PROPERTY);
0918:                frame.addVetoableChangeListener(vetoableListener);
0919:                try {
0920:                    frame.setSelected(true);
0921:                } catch (PropertyVetoException e) {
0922:                    thrown = true;
0923:                } finally {
0924:                    assertTrue("exception is thrown", thrown);
0925:                    assertFalse("isSelected is not set", frame.isSelected());
0926:                    frame.removeVetoableChangeListener(vetoableListener);
0927:                }
0928:                // test set to true when it is iconified
0929:                thrown = false;
0930:                try {
0931:                    frame.setIcon(true);
0932:                    frame.setSelected(true);
0933:                } catch (PropertyVetoException e) {
0934:                    thrown = true;
0935:                } finally {
0936:                    assertFalse("exception is not thrown", thrown);
0937:                    assertTrue("isIcon is set", frame.isIcon());
0938:                    assertTrue("isSelected is set", frame.isSelected());
0939:                }
0940:            }
0941:
0942:            /*
0943:             * Class under test for void JInternalFrame(String, boolean, boolean, boolean, boolean)
0944:             */
0945:            public void testJInternalFrameStringbooleanbooleanbooleanboolean() {
0946:                final String title = "Test title";
0947:                frame = new JInternalFrame(title, true, true, true, true);
0948:                checkJInternalFrameCorrectness(title, true, true, true, true);
0949:                frame = new JInternalFrame(title, true, true, true, false);
0950:                checkJInternalFrameCorrectness(title, true, true, true, false);
0951:                frame = new JInternalFrame(title, true, true, false, true);
0952:                checkJInternalFrameCorrectness(title, true, true, false, true);
0953:            }
0954:
0955:            /*
0956:             * Class under test for void JInternalFrame(String, boolean, boolean, boolean)
0957:             */
0958:            public void testJInternalFrameStringbooleanbooleanboolean() {
0959:                final String title = "Test title";
0960:                frame = new JInternalFrame(title, true, true, true);
0961:                checkJInternalFrameCorrectness(title, true, true, true, false);
0962:                frame = new JInternalFrame(title, false, false, true);
0963:                checkJInternalFrameCorrectness(title, false, false, true, false);
0964:                frame = new JInternalFrame(title, false, true, false);
0965:                checkJInternalFrameCorrectness(title, false, true, false, false);
0966:            }
0967:
0968:            /*
0969:             * Class under test for void JInternalFrame(String, boolean, boolean)
0970:             */
0971:            public void testJInternalFrameStringbooleanboolean() {
0972:                final String title = "Test title";
0973:                frame = new JInternalFrame(title, true, true);
0974:                checkJInternalFrameCorrectness(title, true, true, false, false);
0975:                frame = new JInternalFrame(title, false, true);
0976:                checkJInternalFrameCorrectness(title, false, true, false, false);
0977:                frame = new JInternalFrame(title, true, false);
0978:                checkJInternalFrameCorrectness(title, true, false, false, false);
0979:            }
0980:
0981:            /*
0982:             * Class under test for void JInternalFrame(String, boolean)
0983:             */
0984:            public void testJInternalFrameStringboolean() {
0985:                final String title = "Test title";
0986:                frame = new JInternalFrame(title, false);
0987:                checkJInternalFrameCorrectness(title, false, false, false,
0988:                        false);
0989:                frame = new JInternalFrame(title, true);
0990:                checkJInternalFrameCorrectness(title, true, false, false, false);
0991:            }
0992:
0993:            /*
0994:             * Class under test for void JInternalFrame(String)
0995:             */
0996:            public void testJInternalFrameString() {
0997:                final String title = "Test title";
0998:                frame = new JInternalFrame(title);
0999:                checkJInternalFrameCorrectness(title, false, false, false,
1000:                        false);
1001:            }
1002:
1003:            /*
1004:             * Class under test for void addImpl(Component, Object, int)
1005:             */
1006:            public void testAddImpl() {
1007:                TestInternalFrame frame = new TestInternalFrame();
1008:                JComponent comp = new JPanel();
1009:                // rootPaneCheckingEnabled is true, no exception since 1.5
1010:                frame.setRootPaneCheckingEnabled(true);
1011:                boolean ok = false;
1012:                try {
1013:                    frame.addImpl(comp, null, 0);
1014:                } catch (Error e) {
1015:                    ok = true;
1016:                } finally {
1017:                    assertFalse("no exception", ok);
1018:                    assertTrue("The component is added to contentPane", comp
1019:                            .getParent() == frame.getContentPane());
1020:                }
1021:                // rootPaneCheckingEnabled is false, no exception
1022:                frame.setRootPaneCheckingEnabled(false);
1023:                ok = false;
1024:                try {
1025:                    frame.addImpl(comp, null, 0);
1026:                } catch (Error e) {
1027:                    ok = true;
1028:                } finally {
1029:                    assertFalse("no exception", ok);
1030:                    assertTrue("the component is added to the frame", comp
1031:                            .getParent() == frame);
1032:                    assertTrue("index of the component is 0", frame
1033:                            .getComponent(0) == comp);
1034:                }
1035:            }
1036:
1037:            /*
1038:             * Class under test for void
1039:             *     setUI(InternalFrameUI)
1040:             *     InternalFrameUI getUI()
1041:             */
1042:            public void testSetGetUI() {
1043:                BasicInternalFrameUI ui = new BasicInternalFrameUI(frame);
1044:                frame.setUI(ui);
1045:                assertTrue(frame.getUI() == ui);
1046:            }
1047:
1048:            /*
1049:             * Returns true if array contains obj
1050:             */
1051:            protected boolean contains(final Object[] array, final Object obj) {
1052:                boolean ok = false;
1053:                for (int i = 0; i < array.length; i++) {
1054:                    if (array[i] == obj) {
1055:                        ok = true;
1056:                        break;
1057:                    }
1058:                }
1059:                return ok;
1060:            }
1061:
1062:            /*
1063:             * Class under test for void
1064:             *     void addInternalFrameListener(InternalFrameListener)
1065:             *     removeInternalFrameListener(InternalFrameListener)
1066:             *     InternalFrameListener[] getInternalFrameListeners()
1067:             */
1068:            public void testAddRemoveGetInternalFrameListener() {
1069:                InternalFrameListener l = new MyInternalFrameListener();
1070:                frame.addInternalFrameListener(l);
1071:                InternalFrameListener[] listeners = frame
1072:                        .getInternalFrameListeners();
1073:                assertTrue("listener was added", contains(listeners, l));
1074:                frame.removeInternalFrameListener(l);
1075:                listeners = frame.getInternalFrameListeners();
1076:                assertFalse("listener was removed", contains(listeners, l));
1077:            }
1078:
1079:            /*
1080:             * Class under test for
1081:             *     void setRootPane(JRootPane)
1082:             *     JRootPane getRootPane()
1083:             */
1084:            public void testSetGetRootPane() {
1085:                TestInternalFrame frame = new TestInternalFrame();
1086:                assertTrue("setRootPane() is called from the constructor",
1087:                        TestInternalFrame.setRootPaneCalled);
1088:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1089:                frame.addPropertyChangeListener(
1090:                        JInternalFrame.ROOT_PANE_PROPERTY, listener);
1091:                JRootPane root = new JRootPane();
1092:                frame.setRootPane(root);
1093:                assertTrue(frame.getRootPane() == root);
1094:                assertTrue("rootPane is a bound property", listener.ok);
1095:                // test setting rootPane to null
1096:                frame.setRootPane(null);
1097:                assertNull(frame.getRootPane());
1098:                assertTrue("rootPane is not removed from the container", frame
1099:                        .getComponentCount() == 1);
1100:            }
1101:
1102:            /*
1103:             * Class under test for JRootPane createRootPane()
1104:             */
1105:            public void testCreateRootPane() {
1106:                TestInternalFrame frame = new TestInternalFrame();
1107:                assertTrue("createRootPane() is called from the constructor",
1108:                        TestInternalFrame.createRootPaneCalled);
1109:                JRootPane root = frame.createRootPane();
1110:                assertTrue("createRootPane() cannot return null", root != null);
1111:            }
1112:
1113:            /*
1114:             * Class under test for
1115:             *     void setMenuBar(JMenuBar)
1116:             *     JMenuBar getMenuBar()
1117:             */
1118:            @SuppressWarnings("deprecation")
1119:            public void testSetGetMenuBar() {
1120:                assertNull(frame.getMenuBar());
1121:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1122:                frame.addPropertyChangeListener(
1123:                        JInternalFrame.MENU_BAR_PROPERTY, listener);
1124:                JMenuBar menuBar = new JMenuBar();
1125:                frame.setMenuBar(menuBar);
1126:                assertTrue(frame.getMenuBar() == menuBar);
1127:                assertTrue("menuBar is a bound property", listener.ok);
1128:                frame.setMenuBar(null);
1129:                assertNull(frame.getMenuBar());
1130:            }
1131:
1132:            /*
1133:             * Class under test for
1134:             *     void setJMenuBar(JMenuBar)
1135:             *     JMenuBar getJMenuBar()
1136:             */
1137:            public void testSetGetJMenuBar() {
1138:                assertNull(frame.getJMenuBar());
1139:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1140:                frame.addPropertyChangeListener(
1141:                        JInternalFrame.MENU_BAR_PROPERTY, listener);
1142:                JMenuBar menuBar = new JMenuBar();
1143:                frame.setJMenuBar(menuBar);
1144:                assertTrue(frame.getJMenuBar() == menuBar);
1145:                assertTrue("menuBar is a bound property", listener.ok);
1146:                frame.setJMenuBar(null);
1147:                assertNull(frame.getJMenuBar());
1148:            }
1149:
1150:            /*
1151:             * Class under test for
1152:             *     void setLayeredPane(JLayeredPane)
1153:             *     JLayeredPane getLayeredPane()
1154:             */
1155:            public void testSetGetLayeredPane() {
1156:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1157:                frame.addPropertyChangeListener(
1158:                        JInternalFrame.LAYERED_PANE_PROPERTY, listener);
1159:                JLayeredPane pane = new JLayeredPane();
1160:                frame.setLayeredPane(pane);
1161:                assertTrue(frame.getLayeredPane() == pane);
1162:                assertTrue("layeredPane is a bound property", listener.ok);
1163:                // test throwing exception if the parameter is null
1164:                boolean ok = false;
1165:                try {
1166:                    frame.setLayeredPane(null);
1167:                } catch (IllegalComponentStateException e) {
1168:                    ok = true;
1169:                } finally {
1170:                    assertTrue(ok);
1171:                }
1172:                // layeredPane cannot be null, even after setLayeredPane(null)
1173:                assertTrue(frame.getLayeredPane() != null);
1174:                // setLayeredPane() method is not called by the constructor
1175:                // (seems that there is an error in docs)
1176:            }
1177:
1178:            /*
1179:             * Class under test for void
1180:             *     setDesktopIcon(JDesktopIcon)
1181:             *     JDesktopIcon getDesktopIcon()
1182:             */
1183:            public void testSetGetDesktopIcon() {
1184:                assertTrue("desktopIcon is not null by default", frame
1185:                        .getDesktopIcon() != null);
1186:                JInternalFrame.JDesktopIcon icon = new JInternalFrame.JDesktopIcon(
1187:                        frame);
1188:                assertTrue("desktopIcon is not set",
1189:                        frame.getDesktopIcon() != icon);
1190:                frame.setDesktopIcon(icon);
1191:                assertTrue("desktopIcon is set", frame.getDesktopIcon() == icon);
1192:                frame.setDesktopIcon(null);
1193:                assertNull("desktopIcon is null", frame.getDesktopIcon());
1194:            }
1195:
1196:            /*
1197:             * Class under test for JDesktopPane getDesktopPane()
1198:             */
1199:            public void testGetDesktopPane() throws NullPointerException {
1200:                // no desktopPane
1201:                assertNull("desktopPane is null by default", frame
1202:                        .getDesktopPane());
1203:                //JInternalFrame.JDesktopIcon icon = new JInternalFrame.JDesktopIcon(frame);
1204:                //frame.setDesktopIcon(icon);
1205:                JDesktopPane desktop = new JDesktopPane();
1206:                // frame is added to desktopPane
1207:                desktop.add(frame);
1208:                assertTrue("desktopPane is set",
1209:                        frame.getDesktopPane() == desktop);
1210:                // frame is removed from desktopPane
1211:                desktop.remove(frame);
1212:                assertNull("desktopPane is null", frame.getDesktopPane());
1213:                // icon is added to desktoPane
1214:                desktop.add(frame.getDesktopIcon());
1215:                assertTrue("desktopPane is set",
1216:                        frame.getDesktopPane() == desktop);
1217:                // icon is removed from desktopPane, desktopIcon == null
1218:                // default implementation crashes here
1219:                //desktop.remove(frame.getDesktopIcon());
1220:                //frame.setDesktopIcon(null);
1221:                //assertNull("desktopPane is null", frame.getDesktopPane());
1222:
1223:                JInternalFrame jf = new JInternalFrame();
1224:                JInternalFrame.JDesktopIcon fc = new JInternalFrame.JDesktopIcon(
1225:                        jf);
1226:                fc.setInternalFrame(null);
1227:                assertNull(fc.getDesktopPane());
1228:            }
1229:
1230:            /*
1231:             * Class under test for
1232:             *     void setFrameIcon(Icon)
1233:             *     Icon getFrameIcon()
1234:             */
1235:            public void testSetGetFrameIcon() {
1236:                Icon icon = new ImageIcon();
1237:                assertTrue("frameIcon is not null by default", frame
1238:                        .getFrameIcon() != null);
1239:                frame.setFrameIcon(icon);
1240:                assertTrue("frameIcon is set", frame.getFrameIcon() == icon);
1241:                frame.setFrameIcon(null);
1242:                assertNull("frameIcon is set to null", frame.getFrameIcon());
1243:            }
1244:
1245:            /*
1246:             * Class under test for AccessibleContext getAccessibleContext()
1247:             */
1248:            public void testGetAccessibleContext() {
1249:                AccessibleContext c = frame.getAccessibleContext();
1250:                assertTrue("instanceof AccessibleJInternalFrame",
1251:                        c instanceof  JInternalFrame.AccessibleJInternalFrame);
1252:                // test getAccessibleName()
1253:                assertTrue("AccessibleName is ok", c.getAccessibleName() == "");
1254:                frame.setTitle("aa");
1255:                assertTrue("AccessibleName is ok",
1256:                        c.getAccessibleName() == "aa");
1257:                // test getAccessibleRole()
1258:                assertTrue("AccessibleRole ok",
1259:                        c.getAccessibleRole() == AccessibleRole.INTERNAL_FRAME);
1260:                // test getAccessibleValue()
1261:                assertTrue("AccessibleValue ok", c.getAccessibleValue() == c);
1262:                // test setCurrentAccessibleValue(), getCurrentAccessibleValue()
1263:                AccessibleValue value = c.getAccessibleValue();
1264:                assertTrue("currentAccessibleValue == 0", value
1265:                        .getCurrentAccessibleValue().intValue() == 0);
1266:                Integer currentAccessibleValue = new Integer(4);
1267:                boolean set = value
1268:                        .setCurrentAccessibleValue(currentAccessibleValue);
1269:                assertTrue("setCurrentAccessibleValue returns true", set);
1270:                set = value.setCurrentAccessibleValue(new Float(5));
1271:                assertTrue("setCurrentAccessibleValue returns true", set);
1272:                assertTrue("currentAccessibleValue == 5", value
1273:                        .getCurrentAccessibleValue().intValue() == 5);
1274:                assertTrue("the object is not the same", value
1275:                        .getCurrentAccessibleValue() != currentAccessibleValue);
1276:                set = value.setCurrentAccessibleValue(null);
1277:                assertFalse("setCurrentAccessibleValue returns false", set);
1278:                // test getMinimumAccessibleValue()
1279:                assertTrue(
1280:                        "minimumAccessibleValue ok",
1281:                        value.getMinimumAccessibleValue().intValue() == Integer.MIN_VALUE);
1282:                // test getMaximumAccessibleValue()
1283:                assertTrue(
1284:                        "maximumAccessibleValue ok",
1285:                        value.getMaximumAccessibleValue().intValue() == Integer.MAX_VALUE);
1286:                // test other methods
1287:                assertNull("AccessibleDescription is ok", c
1288:                        .getAccessibleDescription());
1289:                assertTrue("AccessibleChildrenCount == 1", c
1290:                        .getAccessibleChildrenCount() == 1);
1291:            }
1292:
1293:            /*
1294:             * Class under test for
1295:             *     void setTitle(String)
1296:             *     String getTitle()
1297:             */
1298:            public void testSetGetTitle() {
1299:                final String title = "Test title";
1300:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1301:                frame.addPropertyChangeListener(JInternalFrame.TITLE_PROPERTY,
1302:                        listener);
1303:                assertTrue("Default title is an empty title",
1304:                        frame.getTitle() == "");
1305:                // test setting the correct title
1306:                frame.setTitle(title);
1307:                assertTrue("Title is set correctly", frame.getTitle() == title);
1308:                assertTrue("title is a bound property", listener.ok);
1309:                // test setting null title
1310:                frame.setTitle(null);
1311:                assertNull("Title is set to null", frame.getTitle());
1312:            }
1313:
1314:            /*
1315:             * Class under test for String paramString()
1316:             */
1317:            public void testParamString() {
1318:                TestInternalFrame frame = new TestInternalFrame();
1319:                assertTrue("paramString() cannot return null", frame
1320:                        .paramString() != null);
1321:            }
1322:
1323:            /*
1324:             * Class under test for String getUIClassID()
1325:             */
1326:            public void testGetUIClassID() {
1327:                assertTrue("InternalFrameUI" == frame.getUIClassID());
1328:            }
1329:
1330:            /*
1331:             * Class under test for
1332:             *     void setNormalBounds(Rectangle)
1333:             *     Rectangle getNormalBounds()
1334:             */
1335:            public void testSetGetNormalBounds() {
1336:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1337:                frame.addPropertyChangeListener(listener);
1338:                JDesktopPane desktopPane = new JDesktopPane();
1339:                desktopPane.add(frame);
1340:                Rectangle normal = new Rectangle(100, 150); // normal bounds
1341:                Rectangle bounds = new Rectangle(150, 200); // bounds
1342:                frame.setBounds(bounds);
1343:                assertTrue("normalBounds is not null by default", frame
1344:                        .getNormalBounds() != null);
1345:                assertFalse("normalBounds is not affected by setBounds()",
1346:                        frame.getNormalBounds() == bounds);
1347:                frame.setNormalBounds(normal);
1348:                assertFalse("bounds is not affected by setNormalBounds()",
1349:                        frame.getBounds() == normal);
1350:                // test getNormalBounds() when isMaximum == false
1351:                try {
1352:                    frame.setMaximum(false);
1353:                } catch (PropertyVetoException e) {
1354:                    assertTrue("no exception should be thrown", false);
1355:                }
1356:                assertTrue("normalBounds is set",
1357:                        frame.getNormalBounds() == normal);
1358:                assertFalse("normalBounds is not a bound property", listener.ok);
1359:                // test getNormalBounds() when isMaximum == true
1360:                try {
1361:                    frame.setMaximum(true);
1362:                } catch (PropertyVetoException e) {
1363:                    assertTrue("no exception should be thrown", false);
1364:                }
1365:                assertTrue("normalBounds is set", frame.getNormalBounds()
1366:                        .equals(bounds));
1367:                assertFalse("normalBounds is set",
1368:                        frame.getNormalBounds() == bounds);
1369:            }
1370:
1371:            /*
1372:             * Class under test for void setLayout(LayoutManager)
1373:             */
1374:            public void testSetLayout() {
1375:                TestInternalFrame frame = new TestInternalFrame();
1376:                LayoutManager contentLayout = frame.getContentPane()
1377:                        .getLayout();
1378:                LayoutManager frameLayout = frame.getLayout();
1379:                // rootPaneCheckingEnabled is true, no exception since 1.5
1380:                frame.setRootPaneCheckingEnabled(true);
1381:                boolean ok = false;
1382:                try {
1383:                    frame.setLayout(new FlowLayout());
1384:                } catch (Error e) {
1385:                    ok = true;
1386:                } finally {
1387:                    assertFalse("no exception since 1.5", ok);
1388:                    assertTrue("contentPane layout is changed", frame
1389:                            .getContentPane().getLayout() != contentLayout);
1390:                    assertTrue("Frame layout shouldn't be changed", frame
1391:                            .getLayout() == frameLayout);
1392:                    frame.getContentPane().setLayout(contentLayout);
1393:                }
1394:                // rootPaneCheckingEnabled is false
1395:                frame.setRootPaneCheckingEnabled(false);
1396:                ok = false;
1397:                try {
1398:                    frame.setLayout(new FlowLayout());
1399:                } catch (Error e) {
1400:                    ok = true;
1401:                } finally {
1402:                    assertFalse("no exception", ok);
1403:                    assertTrue("contentPane layout shouldn't be changed", frame
1404:                            .getContentPane().getLayout() == contentLayout);
1405:                    assertTrue("Frame layout is changed",
1406:                            frame.getLayout() != frameLayout);
1407:                }
1408:            }
1409:
1410:            /*
1411:             * Class under test for void paintComponent(Graphics)
1412:             */
1413:            public void testPaintComponent() {
1414:                // Note: painting code, cannot test
1415:            }
1416:
1417:            /*
1418:             * Class under test for
1419:             *     void setContentPane(Container)
1420:             *     Container getContentPane()
1421:             */
1422:            public void testSetGetContentPane() {
1423:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1424:                frame.addPropertyChangeListener(
1425:                        JInternalFrame.CONTENT_PANE_PROPERTY, listener);
1426:                JPanel pane = new JPanel();
1427:                frame.setContentPane(pane);
1428:                assertTrue(frame.getContentPane() == pane);
1429:                assertTrue("contentPane is a bound property", listener.ok);
1430:                // test throwing exception if the parameter is null
1431:                boolean ok = false;
1432:                try {
1433:                    frame.setContentPane(null);
1434:                } catch (IllegalComponentStateException e) {
1435:                    ok = true;
1436:                } finally {
1437:                    assertTrue(ok);
1438:                }
1439:                // contentPane cannot be null, even after setContentPane(null)
1440:                assertTrue(frame.getContentPane() != null);
1441:                // setContentPane() method is not called by the constructor
1442:                // (seems that there is an error in docs)
1443:            }
1444:
1445:            /*
1446:             * Class under test for
1447:             *     void setGlassPane(Component)
1448:             *     Component getGlassPane()
1449:             */
1450:            public void testSetGetGlassPane() {
1451:                MyPropertyChangeListener listener = new MyPropertyChangeListener();
1452:                frame.addPropertyChangeListener(
1453:                        JInternalFrame.GLASS_PANE_PROPERTY, listener);
1454:                JPanel pane = new JPanel();
1455:                frame.setGlassPane(pane);
1456:                assertTrue(frame.getGlassPane() == pane);
1457:                assertTrue("glassPane is a bound property", listener.ok);
1458:                // test throwing exception if the parameter is null
1459:                boolean ok = false;
1460:                try {
1461:                    frame.setGlassPane(null);
1462:                } catch (NullPointerException e) {
1463:                    ok = true;
1464:                } finally {
1465:                    assertTrue(ok);
1466:                }
1467:                // glassPane cannot be null, even after setGlassPane(null)
1468:                assertTrue(frame.getGlassPane() != null);
1469:                // setGlassPane() method is not called by the constructor
1470:                // (seems that there is an error in docs)
1471:            }
1472:
1473:            /*
1474:             * Class under test for void remove(Component)
1475:             */
1476:            public void testRemove() {
1477:                JComponent comp = new JPanel();
1478:                frame.getContentPane().add(comp);
1479:                assertTrue("label is in contentPane", frame.isAncestorOf(comp));
1480:                frame.remove(comp);
1481:                assertFalse("label is removed from contentPane", frame
1482:                        .isAncestorOf(comp));
1483:                ((JPanel) frame.getGlassPane()).add(comp);
1484:                frame.remove(comp);
1485:                assertTrue("label is not removed from glassPane", frame
1486:                        .isAncestorOf(comp));
1487:                // test removing from JInternalFrame
1488:                frame.setRootPaneCheckingEnabled(false);
1489:                frame.add(comp);
1490:                assertTrue("added", comp.getParent() == frame);
1491:                frame.remove(comp);
1492:                assertTrue("removed", comp.getParent() != frame);
1493:                // test removing null
1494:                boolean ok = false;
1495:                try {
1496:                    frame.remove((Component) null);
1497:                } catch (NullPointerException e) {
1498:                    ok = true;
1499:                } finally {
1500:                    assertTrue("exception", ok);
1501:                }
1502:                // test removing rootPane
1503:                assertTrue(frame.isAncestorOf(frame.getRootPane()));
1504:                frame.remove(frame.getRootPane());
1505:                // rootPane is removed from the container
1506:                assertFalse(frame.isAncestorOf(frame.getRootPane()));
1507:                // but getRootPane() still returns it
1508:                assertTrue(frame.getRootPane() != null);
1509:            }
1510:
1511:            /*
1512:             * Creates and shows rootFrame. This method is used when JInternalFrame
1513:             * need to be selected (isSelected() == true) for testing purposes.
1514:             */
1515:            protected void createAndShowRootFrame() {
1516:                frame.setSize(70, 100);
1517:                rootFrame = new JFrame();
1518:                JDesktopPane desktop = new JDesktopPane();
1519:                rootFrame.setContentPane(desktop);
1520:                rootFrame.getContentPane().add(frame);
1521:                rootFrame.setSize(100, 200);
1522:                frame.setVisible(true);
1523:                rootFrame.setVisible(true);
1524:            }
1525:
1526:            /*
1527:             * Thread safe function to make the internal frame selected
1528:             * or deselected
1529:             */
1530:            protected void setSelectedFrame(final JInternalFrame frame,
1531:                    final boolean selected) {
1532:                //try {
1533:                //    SwingUtilities.invokeAndWait(new Runnable() {
1534:                //        public void run() {
1535:                try {
1536:                    frame.setSelected(selected);
1537:                } catch (PropertyVetoException e) {
1538:                }
1539:                //        }
1540:                //    });
1541:                //} catch (Exception e) {
1542:                //    assertFalse("exception", true);
1543:                //}
1544:            }
1545:
1546:            /*
1547:             * Class under test for String getWarningString()
1548:             */
1549:            public void testGetWarningString() {
1550:                assertNull("getWarningString() always returns null", frame
1551:                        .getWarningString());
1552:            }
1553:
1554:            /*
1555:             * Class under test for
1556:             *     void setFocusCycleRoot(boolean)
1557:             *     boolean isFocusCycleRoot()
1558:             */
1559:            public void testFocusCycleRoot() {
1560:                assertTrue("isFocusCycleRoot is always true", frame
1561:                        .isFocusCycleRoot());
1562:                frame.setFocusCycleRoot(false);
1563:                assertTrue("isFocusCycleRoot is always true", frame
1564:                        .isFocusCycleRoot());
1565:                frame.setFocusCycleRoot(true);
1566:                assertTrue("isFocusCycleRoot is always true", frame
1567:                        .isFocusCycleRoot());
1568:            }
1569:
1570:            /*
1571:             * Class under test for Container getFocusCycleRootAncestor()
1572:             */
1573:            public void testGetFocusCycleRootAncestor() {
1574:                assertNull("always returns null", frame
1575:                        .getFocusCycleRootAncestor());
1576:            }
1577:
1578:            /*
1579:             * Class under test for void hide()
1580:             */
1581:            public void testHide() {
1582:                frame.setVisible(true);
1583:                frame.hide();
1584:                assertFalse("frame is hided", frame.isVisible());
1585:                if (isHarmony()) {
1586:                    assertFalse("icon is hided", frame.getDesktopIcon()
1587:                            .isVisible());
1588:                }
1589:            }
1590:
1591:            /*
1592:             * Class under test for void show()
1593:             */
1594:            public void testShow() {
1595:                MyInternalFrameListener l = new MyInternalFrameListener();
1596:                frame.addInternalFrameListener(l);
1597:                frame.show();
1598:                assertTrue("INTERNAL_FRAME_OPENED was fired", l.openedFired());
1599:                assertTrue("frame is visible", frame.isVisible());
1600:                assertTrue("icon is visible", frame.getDesktopIcon()
1601:                        .isVisible());
1602:                assertFalse("is selected", frame.isSelected());
1603:                // test show() the first time
1604:                frame = new JInternalFrame();
1605:                frame.addInternalFrameListener(l);
1606:                l.state = 0;
1607:                createAndShowRootFrame();
1608:                assertTrue("INTERNAL_FRAME_OPENED was fired", l.openedFired());
1609:                // test show() the second time
1610:                frame.dispose();
1611:                JInternalFrame frame2 = new JInternalFrame("frame2");
1612:                frame2.setSize(new Dimension(50, 60));
1613:                rootFrame.getContentPane().add(frame2);
1614:                frame2.setVisible(true);
1615:                rootFrame.getContentPane().add(frame);
1616:                l.state = 0;
1617:                frame.show();
1618:                assertFalse("INTERNAL_FRAME_OPENED was not fired", l
1619:                        .openedFired());
1620:                assertTrue("moved to the front", ((JLayeredPane) rootFrame
1621:                        .getContentPane()).getIndexOf(frame) == 0);
1622:                assertTrue("is visible", frame.isVisible());
1623:                assertTrue("is selected", frame.isSelected());
1624:                // test when the frame is already shown
1625:                frame.show();
1626:                assertFalse("INTERNAL_FRAME_OPENED was not fired", l
1627:                        .openedFired());
1628:                // test show() when the internal frame is iconified
1629:                try {
1630:                    frame.setIcon(true);
1631:                } catch (PropertyVetoException e) {
1632:                }
1633:                frame.setVisible(false);
1634:                frame.show();
1635:            }
1636:
1637:            /*
1638:             * Class under test for void dispose()
1639:             */
1640:            public void testDispose() {
1641:                createAndShowRootFrame();
1642:                MyInternalFrameListener l = new MyInternalFrameListener();
1643:                frame.addInternalFrameListener(l);
1644:                // test when the internal frame is visible
1645:                l.state = 0;
1646:                MyPropertyChangeListener l2 = new MyPropertyChangeListener();
1647:                frame.addPropertyChangeListener(
1648:                        JInternalFrame.IS_CLOSED_PROPERTY, l2);
1649:                frame.dispose();
1650:                assertTrue("isClosed property change fired", l2.ok);
1651:                assertFalse("is visible", frame.isVisible());
1652:                assertFalse("is selected", frame.isSelected());
1653:                assertTrue("is closed", frame.isClosed());
1654:                assertTrue("INTERNAL_FRAME_CLOSED was fired", l.closedFired());
1655:                assertFalse("INTERNAL_FRAME_CLOSING was not fired", l
1656:                        .closingFired());
1657:                assertFalse("removed from the containter", rootFrame
1658:                        .isAncestorOf(frame));
1659:                // test already disposed internal frame
1660:                l.state = 0;
1661:                frame.dispose();
1662:                if (isHarmony()) {
1663:                    assertFalse("INTERNAL_FRAME_CLOSED was not fired", l
1664:                            .closedFired());
1665:                }
1666:            }
1667:
1668:            public void testSetBounds() throws Exception {
1669:                // Regression for HARMONY-1801
1670:                final Marker validateMarker = new Marker();
1671:                final Marker revalidateMarker = new Marker();
1672:                final JComponent frame = new JInternalFrame() {
1673:                    @Override
1674:                    public void validate() {
1675:                        validateMarker.setOccurred();
1676:                        super .validate();
1677:                    }
1678:
1679:                    @Override
1680:                    public void revalidate() {
1681:                        revalidateMarker.setOccurred();
1682:                        super .revalidate();
1683:                    }
1684:                };
1685:                validateMarker.reset();
1686:                revalidateMarker.reset();
1687:                frame.setBounds(0, 0, 50, 500);
1688:                assertFalse(revalidateMarker.isOccurred());
1689:                assertTrue(validateMarker.isOccurred());
1690:            }
1691:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.