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.plaf.basic;
021:
022: import java.awt.BorderLayout;
023: import java.awt.Dimension;
024: import java.awt.LayoutManager;
025: import java.awt.event.ComponentListener;
026: import java.beans.PropertyChangeListener;
027: import java.beans.PropertyVetoException;
028: import javax.swing.BorderFactory;
029: import javax.swing.DesktopManager;
030: import javax.swing.InputMap;
031: import javax.swing.JButton;
032: import javax.swing.JComponent;
033: import javax.swing.JDesktopPane;
034: import javax.swing.JFrame;
035: import javax.swing.JInternalFrame;
036: import javax.swing.SwingTestCase;
037: import javax.swing.SwingUtilities;
038: import javax.swing.UIManager;
039: import javax.swing.event.MouseInputAdapter;
040: import javax.swing.event.MouseInputListener;
041: import javax.swing.plaf.ComponentUI;
042:
043: public class BasicInternalFrameUITest extends SwingTestCase {
044:
045: private class MyJInternalFrame extends JInternalFrame {
046: private static final long serialVersionUID = 1L;
047:
048: @Override
049: protected boolean isRootPaneCheckingEnabled() {
050: return false;
051: }
052: }
053:
054: private MyJInternalFrame frame;
055:
056: private BasicInternalFrameUI ui;
057:
058: /*
059: * @see TestCase#setUp()
060: */
061: @Override
062: protected void setUp() throws Exception {
063: super .setUp();
064: frame = new MyJInternalFrame();
065: ui = new BasicInternalFrameUI(frame);
066: }
067:
068: /*
069: * @see TestCase#tearDown()
070: */
071: @Override
072: protected void tearDown() throws Exception {
073: super .tearDown();
074: UIManager.getDefaults().remove("InternalFrame.windowBindings");
075: }
076:
077: private boolean belongs(final Object o, final Object[] array) {
078: for (int i = 0; i < array.length; i++) {
079: if (array[i] == o) {
080: return true;
081: }
082: }
083: return false;
084: }
085:
086: /*
087: * Class under test for void createInternalFrameListener()
088: */
089: public void testCreateInternalFrameListener() {
090: // cannot test createInternalFrameListener() directly, because
091: // it only sets BasicInternalFrameUI.internalFrameListener field
092: // which is private
093: frame.setUI(ui);
094: ui.uninstallKeyboardActions();
095: int listenersCount = frame.getInternalFrameListeners().length;
096: ui.installKeyboardActions();
097: assertTrue(
098: "internalFrameListener was installed",
099: frame.getInternalFrameListeners().length == listenersCount + 1);
100: }
101:
102: /*
103: * Class under test for
104: * void installComponents()
105: * void uninstallComponents()
106: */
107: public void testInstallUninstallComponents() {
108: ui.frame = frame;
109: ui.installComponents();
110: assertTrue("titlePane installed", belongs(ui.titlePane, frame
111: .getComponents()));
112: assertTrue("northPane != null", ui.getNorthPane() != null);
113: // cannot call uninstallComponents() directly
114: ui.uninstallComponents();
115: assertFalse("titlePane uninstalled", belongs(ui.titlePane,
116: frame.getComponents()));
117: assertNull("northPane == null", ui.getNorthPane());
118: }
119:
120: /*
121: * Class is under test for void installDefaults()
122: */
123: public void testInstallDefaults() {
124: frame.setBackground(null);
125: frame.setBorder(null);
126: frame.setFrameIcon(null);
127: frame.setLayout(null);
128: ui.frame = frame;
129: ui.installDefaults();
130: assertTrue("background", frame.getBackground() != null);
131: assertTrue("opaque", frame.isOpaque());
132: assertTrue("border", frame.getBorder() != null);
133: assertTrue("frameIcon", frame.getFrameIcon() != null);
134: assertTrue("layout", frame.getLayout() != null);
135: assertTrue("layout", ui.internalFrameLayout == frame
136: .getLayout());
137: }
138:
139: /*
140: * Class is under test for void uninstallDefaults()
141: */
142: public void testUninstallDefaults() {
143: frame.setUI(ui);
144: // test general uninstallDefaults()
145: ui.uninstallDefaults();
146: assertTrue("background", frame.getBackground() != null);
147: assertNull("border", frame.getBorder());
148: assertNull("frameIcon", frame.getFrameIcon());
149: assertNull("layout", frame.getLayout());
150: assertNull("layout", ui.internalFrameLayout);
151: // test uninstallDefaults() with user-set values
152: frame.setBorder(BorderFactory.createEmptyBorder());
153: frame.setLayout(new BorderLayout());
154: ui.uninstallDefaults();
155: assertTrue("background", frame.getBorder() != null);
156: assertNull("layout", frame.getLayout());
157: }
158:
159: /*
160: * Class is under test for void installKeyboardActions()
161: */
162: public void testInstallKeyboardActions() {
163: UIManager.getDefaults().put("InternalFrame.windowBindings",
164: new Object[] { "shift ESCAPE", "showSystemMenu" });
165: frame.setUI(ui);
166: ui.uninstallKeyboardActions();
167: int listenersCount = frame.getInternalFrameListeners().length;
168: assertNull("no UIActionMap", SwingUtilities
169: .getUIActionMap(frame));
170: ui.installKeyboardActions();
171: assertTrue("UIActionMap installed", SwingUtilities
172: .getUIActionMap(frame) != null);
173: assertTrue(
174: "internalFrameListener istalled",
175: frame.getInternalFrameListeners().length == listenersCount + 1);
176: assertNull("inputMap not installed",
177: SwingUtilities.getUIInputMap(frame,
178: JComponent.WHEN_IN_FOCUSED_WINDOW));
179: }
180:
181: /*
182: * Class is under test for void uninstallKeyboardActions()
183: */
184: public void testUninstallKeyboardActions() {
185: UIManager.getDefaults().put("InternalFrame.windowBindings",
186: new Object[] { "shift ESCAPE", "showSystemMenu" });
187: frame.setUI(ui);
188: ui.setupMenuOpenKey();
189: int listenersCount = frame.getInternalFrameListeners().length;
190: assertTrue("UIActionMap installed", SwingUtilities
191: .getUIActionMap(frame) != null);
192: assertTrue("inputMap installed", SwingUtilities.getUIInputMap(
193: frame, JComponent.WHEN_IN_FOCUSED_WINDOW) != null);
194: ui.uninstallKeyboardActions();
195: assertNull("no UIActionMap", SwingUtilities
196: .getUIActionMap(frame));
197: assertTrue(
198: "internalFrameListener unistalled",
199: frame.getInternalFrameListeners().length == listenersCount - 1);
200: assertNull("inputMap uninstalled",
201: SwingUtilities.getUIInputMap(frame,
202: JComponent.WHEN_IN_FOCUSED_WINDOW));
203: }
204:
205: /*
206: * Class under test for void installListeners()
207: */
208: public void testInstallListeners() {
209: JFrame f = new JFrame();
210: f.setSize(50, 100);
211: f.getContentPane().add(frame);
212: f.setVisible(true);
213: frame.setUI(ui);
214: // glassPaneDispatcher
215: assertTrue("glassPaneDispatcher != null",
216: ui.glassPaneDispatcher != null);
217: assertTrue("glassPaneDispatcher is mouse listener", belongs(
218: ui.glassPaneDispatcher, frame.getGlassPane()
219: .getMouseListeners()));
220: assertTrue("glassPaneDispatcher is mouse motion listener",
221: belongs(ui.glassPaneDispatcher, frame.getGlassPane()
222: .getMouseMotionListeners()));
223: // borderListener
224: assertTrue("borderListener != null", ui.borderListener != null);
225: assertTrue("borderListener is mouse listener", belongs(
226: ui.borderListener, frame.getMouseListeners()));
227: assertTrue("borderListener is mouse motion listener", belongs(
228: ui.borderListener, frame.getMouseMotionListeners()));
229: // propertyChangeListener
230: assertTrue("propertyChangeListener != null",
231: ui.propertyChangeListener != null);
232: assertTrue("propertyChangeListener installed", belongs(
233: ui.propertyChangeListener, frame
234: .getPropertyChangeListeners()));
235: // componentListener
236: assertTrue("componentListener != null",
237: ui.componentListener != null);
238: assertTrue("componentListener installed", belongs(
239: ui.componentListener, frame.getParent()
240: .getComponentListeners()));
241: f.dispose();
242: }
243:
244: /*
245: * Class under test for void uninstallListeners()
246: */
247: public void testUninstallListeners() {
248: JFrame f = new JFrame();
249: f.setSize(50, 100);
250: f.getContentPane().add(frame);
251: f.setVisible(true);
252: frame.setUI(ui);
253: ui.uninstallListeners();
254: // glassPaneDispatcher
255: assertFalse("glassPaneDispatcher is not mouse listener",
256: belongs(ui.glassPaneDispatcher, frame.getGlassPane()
257: .getMouseListeners()));
258: assertFalse("glassPaneDispatcher is not mouse motion listener",
259: belongs(ui.glassPaneDispatcher, frame.getGlassPane()
260: .getMouseMotionListeners()));
261: // borderListener
262: assertFalse("borderListener is not mouse listener", belongs(
263: ui.borderListener, frame.getMouseListeners()));
264: assertFalse("borderListener is not mouse motion listener",
265: belongs(ui.borderListener, frame
266: .getMouseMotionListeners()));
267: // propertyChangeListener
268: assertFalse("propertyChangeListener uninstalled", belongs(
269: ui.propertyChangeListener, frame
270: .getPropertyChangeListeners()));
271: // componentListener
272: assertFalse("componentListener uninstalled", belongs(
273: ui.componentListener, frame.getComponentListeners()));
274: f.dispose();
275: }
276:
277: /*
278: * Class under test for void setupMenuCloseKey()
279: */
280: public void testSetupMenuCloseKey() {
281: // the function does nothing, just check that it doesn't crash
282: ui.setupMenuCloseKey();
283: }
284:
285: /*
286: * Class under test for void setupMenuOpenKey()
287: */
288: public void testSetupMenuOpenKey() {
289: frame.setUI(ui);
290: assertNull("inputMap not installed",
291: SwingUtilities.getUIInputMap(frame,
292: JComponent.WHEN_IN_FOCUSED_WINDOW));
293: // "InternalFrame.windowBindings" is empty - inputMap is not installed
294: final String key = "InternalFrame.windowBindings";
295: if (UIManager.get(key) == null) {
296: ui.setupMenuOpenKey();
297: assertNull("inputMap not installed", SwingUtilities
298: .getUIInputMap(frame,
299: JComponent.WHEN_IN_FOCUSED_WINDOW));
300: }
301: // "InternalFrame.windowBindings" is not empty - inputMap is installed
302: UIManager.getDefaults().put(key,
303: new Object[] { "shift ESCAPE", "showSystemMenu" });
304: ui.setupMenuOpenKey();
305: final InputMap uiInputMap = SwingUtilities.getUIInputMap(frame,
306: JComponent.WHEN_IN_FOCUSED_WINDOW);
307: assertNotNull("inputMap installed", uiInputMap);
308: assertEquals(1, uiInputMap.allKeys().length);
309:
310: // Regression test for HARMONY-2709
311: try {
312: new BasicInternalFrameUI(null).setupMenuOpenKey();
313: fail("NPE expected");
314: } catch (NullPointerException npe) {
315: // PASSED
316: }
317: }
318:
319: /*
320: * Class under test for void BasicInternalFrameUI(JInternalFrame)
321: */
322: public void testBasicInternalFrameUI() {
323: ui = new BasicInternalFrameUI(frame);
324: assertTrue("frame is not set", ui.frame != frame);
325: assertTrue("ui is not installed", frame.getUI() != ui);
326: }
327:
328: /*
329: * Class under test for MouseInputAdapter createBorderListener(JInternalFrame)
330: */
331: public void testCreateBorderListener() {
332: MouseInputAdapter listener1 = ui.createBorderListener(frame);
333: assertTrue("not null", listener1 != null);
334: assertTrue(
335: "instanceof BorderListener",
336: listener1 instanceof BasicInternalFrameUI.BorderListener);
337: MouseInputAdapter listener2 = ui.createBorderListener(frame);
338: assertTrue("new instance", listener1 != listener2);
339: }
340:
341: /*
342: * Class under test for JComponent createWestPane(JInternalFrame)
343: */
344: public void testCreateWestPane() {
345: frame.setUI(ui);
346: assertNull("null", ui.createWestPane(frame));
347: assertNull("null", ui.createWestPane(null));
348: }
349:
350: /*
351: * Class under test for JComponent createSouthPane(JInternalFrame)
352: */
353: public void testCreateSouthPane() {
354: frame.setUI(ui);
355: assertNull("null", ui.createSouthPane(frame));
356: assertNull("null", ui.createSouthPane(null));
357: }
358:
359: /*
360: * Class under test for JComponent createNorthPane(JInternalFrame)
361: */
362: public void testCreateNorthPane() {
363: JComponent comp = ui.createNorthPane(frame);
364: assertTrue("title pane",
365: comp instanceof BasicInternalFrameTitlePane);
366: assertFalse("doesn't belong", belongs(comp, frame
367: .getComponents()));
368: assertTrue("northPane", ui.getNorthPane() != comp);
369: assertTrue("== titlePane", comp == ui.titlePane);
370: JComponent comp2 = ui.createNorthPane(frame);
371: assertTrue("new object", comp != comp2);
372: assertTrue("northPane", ui.getNorthPane() != comp2);
373:
374: try {
375: BasicInternalFrameUIExt f = new BasicInternalFrameUIExt(
376: null);
377: f.createNorthPane(null);
378: fail("NPE should be thrown");
379: } catch (NullPointerException npe) {
380: // PASSED
381: }
382: }
383:
384: class BasicInternalFrameUIExt extends BasicInternalFrameUI {
385: BasicInternalFrameUIExt(JInternalFrame c) {
386: super (c);
387: }
388:
389: public JComponent createNorthPane(JInternalFrame c) {
390: return super .createNorthPane(c);
391: }
392: }
393:
394: /*
395: * Class under test for JComponent createEastPane(JInternalFrame)
396: */
397: public void testCreateEastPane() {
398: frame.setUI(ui);
399: assertNull("null", ui.createEastPane(frame));
400: assertNull("null", ui.createEastPane(null));
401: }
402:
403: /*
404: * Class under test for void replacePane(JComponent, JComponent)
405: */
406: public void testReplacePane() {
407: frame.setUI(ui);
408: JComponent comp = new JButton("OK");
409: // ordinary replace
410: ui.replacePane(ui.getNorthPane(), comp);
411: assertFalse("old pane removed", belongs(ui.getNorthPane(),
412: frame.getComponents()));
413: assertFalse("mouse listener removed", belongs(
414: ui.borderListener, ui.getNorthPane()
415: .getMouseListeners()));
416: assertFalse("mouse motion listener removed", belongs(
417: ui.borderListener, ui.getNorthPane()
418: .getMouseMotionListeners()));
419: assertTrue("new pane added", belongs(comp, frame
420: .getComponents()));
421: assertTrue("mouse listener istalled", belongs(
422: ui.borderListener, comp.getMouseListeners()));
423: assertTrue("mouse motion listener istalled", belongs(
424: ui.borderListener, comp.getMouseMotionListeners()));
425: // replace to null
426: ui.replacePane(comp, null);
427: assertFalse("new pane removed", belongs(comp, frame
428: .getComponents()));
429: assertFalse("mouse listener removed", belongs(
430: ui.borderListener, comp.getMouseListeners()));
431: assertFalse("mouse motion listener removed", belongs(
432: ui.borderListener, comp.getMouseMotionListeners()));
433: }
434:
435: /*
436: * Class under test for Dimension getPreferredSize(JComponent)
437: */
438: public void testGetPreferredSize() {
439: frame.setPreferredSize(new Dimension(200, 200));
440: Dimension standardSize = new Dimension(100, 100);
441: // ui is not installed into the frame
442: assertTrue("standard size", ui.getPreferredSize(frame).equals(
443: standardSize));
444: // ui.getPreferredSize(null) crashes with NullPointerException
445: ui.installUI(frame);
446: // ui is installed into the frame
447: assertTrue("size ok", ui.getPreferredSize(frame).equals(
448: ui.internalFrameLayout.preferredLayoutSize(frame)));
449: assertTrue("standard size", ui.getPreferredSize(null).equals(
450: standardSize));
451: assertTrue("standard size", ui.getPreferredSize(
452: new JInternalFrame()).equals(standardSize));
453: }
454:
455: /*
456: * Class under test for Dimension getMinimumSize(JComponent)
457: */
458: public void testGetMinimumSize() {
459: frame.setMinimumSize(new Dimension(200, 200));
460: Dimension standardSize = new Dimension(0, 0);
461: // ui is not installed into the frame
462: assertTrue("standard size", ui.getMinimumSize(frame).equals(
463: standardSize));
464: // ui.getMinimumSize(null) crashes with NullPointerException
465: ui.installUI(frame);
466: // ui is installed into the frame
467: assertTrue("size ok", ui.getMinimumSize(frame).equals(
468: ui.internalFrameLayout.minimumLayoutSize(frame)));
469: assertTrue("standard size", ui.getMinimumSize(null).equals(
470: standardSize));
471: assertTrue("standard size", ui.getMinimumSize(
472: new JInternalFrame()).equals(standardSize));
473: }
474:
475: /*
476: * Class under test for Dimension getMaximumSize(JComponent)
477: */
478: public void testGetMaximumSize() {
479: ui.installUI(frame);
480: // ui is installed into the frame
481: Dimension size = ui.getMaximumSize(frame);
482: assertTrue(size.width >= Short.MAX_VALUE);
483: assertTrue(size.height >= Short.MAX_VALUE);
484: size = ui.getMaximumSize(null);
485: assertTrue(size.width >= Short.MAX_VALUE);
486: assertTrue(size.height >= Short.MAX_VALUE);
487: }
488:
489: /*
490: * Class under test for MouseInputListener createGlassPaneDispatcher()
491: */
492: public void testCreateGlassPaneDispatcher() {
493: MouseInputListener listener1 = ui.createGlassPaneDispatcher();
494: assertTrue("not null", listener1 != null);
495: assertNotSame(listener1, ui.glassPaneDispatcher);
496: }
497:
498: /*
499: * Class under test for void minimizeFrame(JInternalFrame)
500: */
501: public void testMinimizeFrame() {
502: Dimension size = new Dimension(10, 20);
503: frame.setUI(ui);
504: frame.setSize(size);
505: frame.setMaximizable(true);
506: JDesktopPane desktop = new JDesktopPane();
507: desktop.setSize(new Dimension(100, 200));
508: desktop.add(frame);
509: try {
510: frame.setMaximum(true);
511: } catch (PropertyVetoException e) {
512: assertTrue("exception", false);
513: }
514: assertTrue("size changed", frame.getSize().equals(
515: desktop.getSize()));
516: frame.setMaximizable(false);
517: ui.minimizeFrame(frame);
518: assertFalse("minimized", frame.getSize().equals(
519: desktop.getSize()));
520: }
521:
522: /*
523: * Class under test for void maximizeFrame(JInternalFrame)
524: */
525: public void testMaximizeFrame() {
526: frame.setUI(ui);
527: JDesktopPane desktop = new JDesktopPane();
528: desktop.setSize(new Dimension(100, 200));
529: desktop.add(frame);
530: ui.maximizeFrame(frame);
531: assertTrue("maximized", frame.getSize().equals(
532: desktop.getSize()));
533: }
534:
535: /*
536: * Class under test for void iconifyFrame(JInternalFrame)
537: */
538: public void testIconifyFrame() {
539: frame.setUI(ui);
540: JDesktopPane desktop = new JDesktopPane();
541: desktop.setSize(new Dimension(100, 200));
542: desktop.add(frame);
543: ui.iconifyFrame(frame);
544: assertTrue("iconified", desktop.isAncestorOf(frame
545: .getDesktopIcon()));
546: }
547:
548: /*
549: * Class under test for void deiconifyFrame(JInternalFrame)
550: */
551: public void testDeiconifyFrame() {
552: frame.setUI(ui);
553: JDesktopPane desktop = new JDesktopPane();
554: desktop.setSize(new Dimension(100, 200));
555: desktop.add(frame);
556: frame.setIconifiable(true);
557: try {
558: frame.setIcon(true);
559: } catch (PropertyVetoException e) {
560: assertTrue("exception", false);
561: }
562: assertTrue("iconified", desktop.isAncestorOf(frame
563: .getDesktopIcon()));
564: frame.setIconifiable(false);
565: ui.deiconifyFrame(frame);
566: assertTrue("deiconified", desktop.isAncestorOf(frame));
567: }
568:
569: /*
570: * Class under test for void activateFrame(JInternalFrame)
571: */
572: public void testActivateFrame() {
573: frame.setUI(ui);
574: JDesktopPane desktop = new JDesktopPane();
575: desktop.setSize(new Dimension(100, 200));
576: desktop.add(frame);
577: assertTrue("not selected", desktop.getSelectedFrame() != frame);
578: ui.activateFrame(frame);
579: assertTrue("activated", desktop.getSelectedFrame() == frame);
580: }
581:
582: /*
583: * Class under test for void deactivateFrame(JInternalFrame)
584: */
585: public void testDeactivateFrame() {
586: frame.setUI(ui);
587: JDesktopPane desktop = new JDesktopPane();
588: desktop.setSize(new Dimension(100, 200));
589: desktop.add(frame);
590: ui.activateFrame(frame);
591: assertTrue("activated", desktop.getSelectedFrame() == frame);
592: ui.deactivateFrame(frame);
593: assertTrue("deactivated", desktop.getSelectedFrame() != frame);
594: }
595:
596: /*
597: * Class under test for void closeFrame(JInternalFrame)
598: */
599: public void testCloseFrame() {
600: frame.setUI(ui);
601: JDesktopPane desktop = new JDesktopPane();
602: desktop.setSize(new Dimension(100, 200));
603: desktop.add(frame);
604: ui.closeFrame(frame);
605: assertFalse("frame removed", desktop.isAncestorOf(frame));
606: assertFalse("desktop icon removed", desktop.isAncestorOf(frame
607: .getDesktopIcon()));
608: }
609:
610: /*
611: * Class under test for
612: * void setWestPane(JComponent)
613: * JComponent getWestPane()
614: */
615: public void testSetGetWestPane() {
616: frame.setUI(ui);
617: JButton comp = new JButton("ok");
618: // null by default
619: assertNull("null by default", ui.getWestPane());
620: // general setting
621: ui.setWestPane(comp);
622: assertTrue("was set", ui.getWestPane() == comp);
623: assertTrue("field was set", ui.westPane == comp);
624: assertFalse("not added", belongs(comp, frame.getComponents()));
625: // setting to null
626: ui.setWestPane(null);
627: assertNull("was set", ui.getWestPane());
628: }
629:
630: /*
631: * Class under test for
632: * void setSouthPane(JComponent)
633: * JComponent getSouthPane()
634: */
635: public void testSetGetSouthPane() {
636: frame.setUI(ui);
637: JButton comp = new JButton("ok");
638: // null by default
639: assertNull("null by default", ui.getSouthPane());
640: // general setting
641: ui.setSouthPane(comp);
642: assertTrue("was set", ui.getSouthPane() == comp);
643: assertTrue("field was set", ui.southPane == comp);
644: assertFalse("not added", belongs(comp, frame.getComponents()));
645: // setting to null
646: ui.setSouthPane(null);
647: assertNull("was set", ui.getSouthPane());
648: }
649:
650: /*
651: * Class under test for
652: * void setNorthPane(JComponent)
653: * JComponent getNorthPane()
654: */
655: public void testSetGetNorthPane() {
656: frame.setUI(ui);
657: JComponent comp = new JButton("ok");
658: // not null by default
659: assertTrue("not null by default", ui.getNorthPane() != null);
660: // general setting
661: ui.setNorthPane(comp);
662: assertTrue("was set", ui.getNorthPane() == comp);
663: assertTrue("field was set", ui.northPane == comp);
664: assertTrue("added", belongs(comp, frame.getComponents()));
665: // setting to null
666: ui.setNorthPane(null);
667: assertNull("was set", ui.getNorthPane());
668: }
669:
670: /*
671: * Class under test for
672: * void setEastPane(JComponent)
673: * JComponent getEastPane()
674: */
675: public void testSetGetEastPane() {
676: frame.setUI(ui);
677: JButton comp = new JButton("ok");
678: // null by default
679: assertNull("null by default", ui.getEastPane());
680: // general setting
681: ui.setEastPane(comp);
682: assertTrue("was set", ui.getEastPane() == comp);
683: assertTrue("field was set", ui.eastPane == comp);
684: assertFalse("not added", belongs(comp, frame.getComponents()));
685: // setting to null
686: ui.setEastPane(null);
687: assertNull("was set", ui.getEastPane());
688: }
689:
690: /*
691: * Class under test for ComponentUI createUI(JComponent)
692: */
693: public void testCreateUI() {
694: ComponentUI ui1 = BasicInternalFrameUI.createUI(frame);
695: ComponentUI ui2 = BasicInternalFrameUI.createUI(frame);
696: assertTrue("not null", ui1 != null);
697: assertTrue("statefull", ui1 != ui2);
698: }
699:
700: /*
701: * Class under test for void installUI(JComponent)
702: */
703: public void testInstallUI() {
704: frame.setBorder(null);
705: ui.installUI(frame);
706: // we'll check only some key points
707: assertTrue("installed titlePane", belongs(ui.titlePane, frame
708: .getComponents()));
709: assertTrue("installed border", frame.getBorder() != null);
710: assertTrue("borderListener != null", ui.borderListener != null);
711: assertTrue("installed borderListener", belongs(
712: ui.borderListener, frame.getMouseListeners()));
713: }
714:
715: /*
716: * Class under test for void uninstallUI(JComponent)
717: */
718: public void testUninstallUI() {
719: ui.installUI(frame);
720: ui.uninstallUI(frame);
721: // we'll check only some key points
722: assertFalse("uninstalled titlePane", belongs(ui.titlePane,
723: frame.getComponents()));
724: assertFalse("uninstalled border", frame.getBorder() != null);
725: assertFalse("uninstalled borderListener", belongs(
726: ui.borderListener, frame.getMouseListeners()));
727: }
728:
729: /*
730: * Class under test for void installMouseHandlers(JComponent)
731: */
732: public void testInstallMouseHandlers() {
733: ui.borderListener = ui.createBorderListener(frame);
734: // install to frame
735: ui.installMouseHandlers(frame);
736: assertTrue("mouseListener in frame", belongs(ui.borderListener,
737: frame.getMouseListeners()));
738: assertTrue("mouseMotionListener in frame", belongs(
739: ui.borderListener, frame.getMouseMotionListeners()));
740: // install to titlePane
741: ui.titlePane = new BasicInternalFrameTitlePane(frame);
742: ui.installMouseHandlers(ui.titlePane);
743: assertTrue("mouseListener in titlePane", belongs(
744: ui.borderListener, ui.titlePane.getMouseListeners()));
745: assertTrue("mouseMotionListener in titlePane", belongs(
746: ui.borderListener, ui.titlePane
747: .getMouseMotionListeners()));
748: // JInternalFrame frame = new JInternalFrame();
749: // ui.frame = frame;
750: // System.out.println(frame.getMouseListeners().length);
751: // ui.installMouseHandlers(frame);
752: // System.out.println(frame.getMouseListeners().length);
753: }
754:
755: /*
756: * Class under test for void deinstallMouseHandlers(JComponent)
757: */
758: public void testDeinstallMouseHandlers() {
759: ui.borderListener = ui.createBorderListener(frame);
760: ui.installMouseHandlers(frame);
761: ui.titlePane = new BasicInternalFrameTitlePane(frame);
762: ui.installMouseHandlers(ui.titlePane);
763: // deinstall from frame
764: ui.deinstallMouseHandlers(frame);
765: assertFalse("deinstalled mouseListener from frame", belongs(
766: ui.borderListener, frame.getMouseListeners()));
767: assertFalse("deinstalled mouseMotionListener from frame",
768: belongs(ui.borderListener, frame
769: .getMouseMotionListeners()));
770: // deinstall from titlePane
771: ui.deinstallMouseHandlers(ui.titlePane);
772: assertFalse("deinstalled mouseListener from titlePane",
773: belongs(ui.borderListener, ui.titlePane
774: .getMouseListeners()));
775: assertFalse("deinstalled mouseMotionListener from titlePane",
776: belongs(ui.borderListener, ui.titlePane
777: .getMouseMotionListeners()));
778: }
779:
780: /*
781: * Class under test for DesktopManager getDesktopManager()
782: */
783: public void testGetDesktopManager() {
784: frame.setUI(ui);
785: // no desktop pane, the default desktop manager is created
786: DesktopManager manager1 = ui.getDesktopManager();
787: assertTrue("not null", manager1 != null);
788: DesktopManager manager2 = ui.getDesktopManager();
789: assertTrue("the same object", manager1 == manager2);
790: assertNull("no desktop pane", frame.getDesktopPane());
791: // the desktop pane is set
792: JDesktopPane desktop = new JDesktopPane();
793: desktop.add(frame);
794: manager2 = ui.getDesktopManager();
795: assertTrue("not null", manager2 != null);
796: assertTrue("is taken from desktop pane", manager2 == frame
797: .getDesktopPane().getDesktopManager());
798: assertTrue("another object", manager2 != manager1);
799: }
800:
801: /*
802: * Class under test for DesktopManager createDesktopManager()
803: */
804: public void testCreateDesktopManager() {
805: DesktopManager manager1 = ui.createDesktopManager();
806: assertTrue("not null", manager1 != null);
807: DesktopManager manager2 = ui.createDesktopManager();
808: assertTrue("other object", manager1 != manager2);
809: }
810:
811: /*
812: * Class under test for PropertyChangeListener createPropertyChangeListener()
813: */
814: public void testCreatePropertyChangeListener() {
815: PropertyChangeListener listener1 = ui
816: .createPropertyChangeListener();
817: assertTrue("not null", listener1 != null);
818: PropertyChangeListener listener2 = ui
819: .createPropertyChangeListener();
820: assertTrue("the same object", listener1 == listener2);
821: //assertTrue("is saved", ui.propertyChangeListener == listener1);
822: }
823:
824: /*
825: * Class under test for ComponentListener createComponentListener()
826: */
827: public void testCreateComponentListener() {
828: ComponentListener listener1 = ui.createComponentListener();
829: assertTrue("not null", listener1 != null);
830: assertNotSame(listener1, ui.componentListener);
831: }
832:
833: /*
834: * Class under test for LayoutManager createLayoutManager()
835: */
836: public void testCreateLayoutManager() {
837: LayoutManager layout = ui.createLayoutManager();
838: assertTrue("not null", layout != null);
839: if (isHarmony()) {
840: assertTrue(
841: "instanceof InternalFrameLayout",
842: layout instanceof BasicInternalFrameUI.InternalFrameLayout);
843: }
844: assertNotSame(layout, ui.internalFrameLayout);
845: }
846:
847: /*
848: * Class under test for
849: * void setKeyBindingRegistered()
850: * boolean isKeyBindingRegistered()
851: */
852: public void testSetIsKeyBindingRegistered() {
853: frame.setUI(ui);
854: assertFalse("false by default", ui.isKeyBindingRegistered());
855: ui.setKeyBindingRegistered(true);
856: assertTrue("set to true", ui.isKeyBindingRegistered());
857: ui.setKeyBindingRegistered(false);
858: assertFalse("set to false", ui.isKeyBindingRegistered());
859: }
860:
861: /*
862: * Class under test for
863: * void setKeyBindingActive()
864: * boolean isKeyBindingActive()
865: */
866: public void testSetIsKeyBindingActive() {
867: frame.setUI(ui);
868: assertFalse("false by default", ui.isKeyBindingActive());
869: ui.setKeyBindingActive(true);
870: assertTrue("set to true", ui.isKeyBindingActive());
871: ui.setKeyBindingActive(false);
872: assertFalse("set to false", ui.isKeyBindingActive());
873: }
874:
875: public void testBorderListener() {
876: // the documentation is empty
877: }
878:
879: public void testBasicInternalFrameListener() {
880: // the documentation is empty
881: }
882:
883: public void testComponentHandler() {
884: // the documentation is empty
885: }
886:
887: public void testGlassPaneDispatcher() {
888: // the documentation is empty
889: }
890:
891: public void testInternalFramePropertyChangeListener() {
892: // the documentation is empty
893: }
894: }
|