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.metal;
021:
022: import javax.swing.JComponent;
023: import javax.swing.JInternalFrame;
024: import javax.swing.UIManager;
025: import javax.swing.SwingTestCase;
026: import javax.swing.plaf.ComponentUI;
027:
028: public class MetalInternalFrameUITest extends SwingTestCase {
029: private JInternalFrame frame;
030:
031: private MetalInternalFrameUI ui;
032:
033: /*
034: * @see TestCase#setUp()
035: */
036: @Override
037: protected void setUp() throws Exception {
038: super .setUp();
039: frame = new JInternalFrame();
040: ui = new MetalInternalFrameUI(frame);
041: }
042:
043: /*
044: * @see TestCase#tearDown()
045: */
046: @Override
047: protected void tearDown() throws Exception {
048: super .tearDown();
049: }
050:
051: private boolean belongs(final Object o, final Object[] array) {
052: for (int i = 0; i < array.length; i++) {
053: if (array[i] == o) {
054: return true;
055: }
056: }
057: return false;
058: }
059:
060: /*
061: * Constructor for MetalInternalFrameUITest.
062: * @param name
063: */
064: public MetalInternalFrameUITest(final String name) {
065: super (name);
066: }
067:
068: /*
069: * Class under test for JComponent createNorthPane(JInternalFrame)
070: */
071: public void testCreateNorthPane() {
072: JComponent comp = ui.createNorthPane(frame);
073: assertTrue("not null", comp != null);
074: assertTrue("instanceof MetalInternalFrameTitlePane",
075: comp instanceof MetalInternalFrameTitlePane);
076: JComponent comp2 = ui.createNorthPane(frame);
077: assertTrue("new object", comp != comp2);
078: }
079:
080: /*
081: * Class under test for ComponentUI createUI(JComponent)
082: */
083: public void testCreateUI() {
084: ComponentUI ui = MetalInternalFrameUI.createUI(frame);
085: assertTrue("not null", ui != null);
086: assertTrue("instanceof MetalInternalFrameUI",
087: ui instanceof MetalInternalFrameUI);
088: ComponentUI ui2 = MetalInternalFrameUI.createUI(frame);
089: assertTrue("stateful", ui != ui2);
090: }
091:
092: /*
093: * Class under test for void installUI(JComponent)
094: */
095: public void testInstallUI() {
096: ui.installUI(frame);
097: assertFalse(
098: "false by default",
099: ((MetalInternalFrameTitlePane) ui.getNorthPane()).isPalette);
100: frame.putClientProperty(MetalInternalFrameUI.IS_PALETTE,
101: Boolean.TRUE);
102: ui = new MetalInternalFrameUI(frame);
103: ui.installUI(frame);
104: assertTrue("true", ((MetalInternalFrameTitlePane) ui
105: .getNorthPane()).isPalette);
106: frame.putClientProperty(MetalInternalFrameUI.IS_PALETTE,
107: Boolean.FALSE);
108: ui = new MetalInternalFrameUI(frame);
109: ui.installUI(frame);
110: assertFalse("false again", ((MetalInternalFrameTitlePane) ui
111: .getNorthPane()).isPalette);
112: }
113:
114: /*
115: * Class under test for void uninstallUI(JComponent)
116: */
117: public void testUninstallUI() {
118: // Note: nothing to test
119: }
120:
121: /*
122: * Class under test for void installListeners()
123: */
124: public void testInstallListeners() {
125: frame.setUI(ui);
126: ui.uninstallListeners();
127: ui.installListeners();
128: frame.putClientProperty(MetalInternalFrameUI.IS_PALETTE,
129: Boolean.TRUE);
130: assertTrue(
131: "isPalette of titlePane is true",
132: ((MetalInternalFrameTitlePane) ui.getNorthPane()).isPalette);
133: frame.putClientProperty(MetalInternalFrameUI.IS_PALETTE,
134: Boolean.FALSE);
135: assertFalse(
136: "isPalette of titlePane is false",
137: ((MetalInternalFrameTitlePane) ui.getNorthPane()).isPalette);
138: }
139:
140: /*
141: * Class under test for void uninstallListeners()
142: */
143: public void testUninstallListeners() {
144: frame.setUI(ui);
145: ui.uninstallListeners();
146: frame.putClientProperty(MetalInternalFrameUI.IS_PALETTE,
147: Boolean.TRUE);
148: assertFalse(
149: "isPalette of titlePane is false",
150: ((MetalInternalFrameTitlePane) ui.getNorthPane()).isPalette);
151: }
152:
153: /*
154: * Class under test for void installKeyboardActions()
155: */
156: public void testInstallKeyboardActions() {
157: // Note: nothing to test
158: }
159:
160: /*
161: * Class under test for void uninstallKeyboardActions()
162: */
163: public void testUninstallKeyboardActions() {
164: // Note: nothing to test
165: }
166:
167: /*
168: * Class under test for void uninstallComponents()
169: */
170: public void testUninstallComponents() {
171: frame.setUI(ui);
172: ui.uninstallComponents();
173: assertFalse("titlePane uninstalled", belongs(ui.getNorthPane(),
174: frame.getComponents()));
175: assertNull("northPane == null", ui.getNorthPane());
176: }
177:
178: /*
179: * Class under test for MetalInternalFrameUI(JInternalFrame)
180: */
181: public void testMetalInternalFrameUI() {
182: // nothing to test
183: }
184:
185: /*
186: * Class under test for void setPalette(boolean)
187: */
188: public void testSetPalette() {
189: frame.setUI(ui);
190: ui.setPalette(true);
191: assertTrue(
192: "isPalette of titlePane is true",
193: ((MetalInternalFrameTitlePane) ui.getNorthPane()).isPalette);
194: assertTrue("changed frame border", UIManager.getDefaults()
195: .getBorder("InternalFrame.paletteBorder") == frame
196: .getBorder());
197: // test propertyChangeListener;
198: // ui.setPalette(false) has to be called by the listener
199: frame.putClientProperty(MetalInternalFrameUI.IS_PALETTE,
200: Boolean.FALSE);
201: assertFalse(
202: "isPalette of titlePane is false",
203: ((MetalInternalFrameTitlePane) ui.getNorthPane()).isPalette);
204: assertTrue("changed frame border", UIManager.getDefaults()
205: .getBorder("InternalFrame.border") == frame.getBorder());
206: }
207: }
|