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 java.awt.LayoutManager;
023: import javax.swing.BorderFactory;
024: import javax.swing.JFrame;
025: import javax.swing.JRootPane;
026: import javax.swing.SwingTestCase;
027: import javax.swing.border.Border;
028: import javax.swing.plaf.ComponentUI;
029:
030: public class MetalRootPaneUITest extends SwingTestCase {
031: private JRootPane rootPane;
032:
033: private MetalRootPaneUI ui;
034:
035: private JFrame frame;
036:
037: /*
038: * @see TestCase#setUp()
039: */
040: @Override
041: protected void setUp() throws Exception {
042: super .setUp();
043: frame = new JFrame();
044: rootPane = frame.getRootPane();
045: ui = new MetalRootPaneUI();
046: }
047:
048: /*
049: * @see TestCase#tearDown()
050: */
051: @Override
052: protected void tearDown() throws Exception {
053: super .tearDown();
054: }
055:
056: /*
057: * Constructor for MetalRootPaneUITest.
058: */
059: public MetalRootPaneUITest(final String name) {
060: super (name);
061: }
062:
063: /*
064: * Class under test for void installUI(JComponent)
065: */
066: public void testInstallUI() {
067: // test install with windowDecorationStyle = JRootPane.NONE
068: Border saveBorder = rootPane.getBorder();
069: LayoutManager saveLayout = rootPane.getLayout();
070: int saveComponentCount = rootPane.getLayeredPane()
071: .getComponentCount();
072: ui.installUI(rootPane);
073: assertTrue("didn't install border",
074: rootPane.getBorder() == saveBorder);
075: assertTrue("didn't install layout",
076: rootPane.getLayout() == saveLayout);
077: assertTrue(
078: "didn't install titlePane",
079: rootPane.getLayeredPane().getComponentCount() == saveComponentCount);
080: // test install with windowDecorationStyle = JRootPane.FRAME
081: rootPane.setWindowDecorationStyle(JRootPane.FRAME);
082: ui.uninstallUI(rootPane);
083: saveBorder = rootPane.getBorder();
084: saveLayout = rootPane.getLayout();
085: saveComponentCount = rootPane.getLayeredPane()
086: .getComponentCount();
087: ui.installUI(rootPane);
088: assertTrue("border != null", rootPane.getBorder() != null);
089: assertTrue("installed border",
090: rootPane.getBorder() != saveBorder);
091: assertTrue("layout != null", rootPane.getBorder() != null);
092: assertTrue("installed layout",
093: rootPane.getLayout() != saveLayout);
094: assertTrue("installed titlePane", rootPane.getLayeredPane()
095: .getComponentCount() == saveComponentCount + 1);
096: }
097:
098: /*
099: * Class under test for void uninstallUI(JComponent)
100: */
101: public void testUninstallUI() {
102: // test uninstall with windowDecorationStyle = JRootPane.NONE
103: ui.installUI(rootPane);
104: Border saveBorder = rootPane.getBorder();
105: LayoutManager saveLayout = rootPane.getLayout();
106: int saveComponentCount = rootPane.getLayeredPane()
107: .getComponentCount();
108: ui.uninstallUI(rootPane);
109: assertTrue("didn't uninstall border",
110: rootPane.getBorder() == saveBorder);
111: assertTrue("didn't uninstall layout",
112: rootPane.getLayout() == saveLayout);
113: assertTrue(
114: "didn't uninstall titlePane",
115: rootPane.getLayeredPane().getComponentCount() == saveComponentCount);
116: // test uninstall with windowDecorationStyle = JRootPane.FRAME
117: ui.installUI(rootPane);
118: rootPane.setWindowDecorationStyle(JRootPane.FRAME);
119: saveBorder = rootPane.getBorder();
120: saveLayout = rootPane.getLayout();
121: saveComponentCount = rootPane.getLayeredPane()
122: .getComponentCount();
123: ui.uninstallUI(rootPane);
124: assertTrue("uninstalled border",
125: rootPane.getBorder() != saveBorder);
126: assertTrue("uninstalled layout",
127: rootPane.getLayout() != saveLayout);
128: assertTrue("uninstalled titlePane", rootPane.getLayeredPane()
129: .getComponentCount() == saveComponentCount - 1);
130: }
131:
132: /*
133: * Class under test for void propertyChange(PropertyChangeEvent)
134: */
135: public void testPropertyChange() {
136: rootPane.setUI(ui);
137: Border saveBorder = rootPane.getBorder();
138: LayoutManager saveLayout = rootPane.getLayout();
139: int saveComponentCount = rootPane.getLayeredPane()
140: .getComponentCount();
141: // test windowDecorationStyle = JRootPane.FRAME
142: rootPane.setWindowDecorationStyle(JRootPane.FRAME);
143: assertTrue("border != null", rootPane.getBorder() != null);
144: assertTrue("installed border",
145: rootPane.getBorder() != saveBorder);
146: assertTrue("layout != null", rootPane.getBorder() != null);
147: assertTrue("installed layout",
148: rootPane.getLayout() != saveLayout);
149: assertTrue("installed titlePane", rootPane.getLayeredPane()
150: .getComponentCount() == saveComponentCount + 1);
151: // test windowDecorationStyle = JRootPane.NONE
152: rootPane.setWindowDecorationStyle(JRootPane.NONE);
153: assertTrue("uninstalled border",
154: rootPane.getBorder() == saveBorder);
155: assertTrue("uninstalled layout",
156: rootPane.getLayout() == saveLayout);
157: assertTrue("uninstalled titlePane", rootPane.getLayeredPane()
158: .getComponentCount() == saveComponentCount);
159: // the border is not instanceof UIResource, must not be changed
160: saveBorder = BorderFactory.createEmptyBorder();
161: rootPane.setBorder(saveBorder);
162: assertTrue("didn't install border",
163: rootPane.getBorder() == saveBorder);
164: }
165:
166: /*
167: * Class under test for ComponentUI createUI(JComponent)
168: */
169: public void testCreateUI() {
170: ComponentUI ui = MetalRootPaneUI.createUI(rootPane);
171: assertTrue("not null", ui != null);
172: assertTrue("instanceof MetalRootPaneUI",
173: ui instanceof MetalRootPaneUI);
174: ComponentUI ui2 = MetalRootPaneUI.createUI(rootPane);
175: assertTrue("stateful", ui != ui2);
176: }
177:
178: /*
179: * Class under test for MetalRootPaneUI()
180: */
181: public void testMetalRootPaneUI() {
182: // test that it doesn't crash
183: ui = new MetalRootPaneUI();
184: }
185: }
|