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.Dimension;
023: import javax.swing.JComponent;
024: import javax.swing.JInternalFrame;
025: import javax.swing.SwingTestCase;
026: import javax.swing.UIManager;
027: import javax.swing.plaf.ComponentUI;
028:
029: public class MetalDesktopIconUITest extends SwingTestCase {
030: private TestMetalDesktopIconUI ui;
031:
032: private JInternalFrame.JDesktopIcon icon;
033:
034: private JInternalFrame frame;
035:
036: private class TestMetalDesktopIconUI extends MetalDesktopIconUI {
037: public JComponent getIconPane() {
038: return iconPane;
039: }
040: }
041:
042: /*
043: * @see TestCase#setUp()
044: */
045: @Override
046: protected void setUp() throws Exception {
047: super .setUp();
048: frame = new JInternalFrame();
049: icon = frame.getDesktopIcon();
050: ui = new TestMetalDesktopIconUI();
051: ui.installUI(icon);
052: }
053:
054: /*
055: * @see TestCase#tearDown()
056: */
057: @Override
058: protected void tearDown() throws Exception {
059: super .tearDown();
060: }
061:
062: /**
063: * Constructor for MetalDesktopIconUITest.
064: * @param name
065: */
066: public MetalDesktopIconUITest(final String name) {
067: super (name);
068: }
069:
070: /*
071: * Class under test for ComponentUI createUI(JComponent)
072: */
073: public void testCreateUI() {
074: ComponentUI ui1 = MetalDesktopIconUI.createUI(frame);
075: ComponentUI ui2 = MetalDesktopIconUI.createUI(frame);
076: assertTrue("not null", ui1 != null);
077: assertTrue("statefull", ui1 != ui2);
078: }
079:
080: /*
081: * Class under test for Dimension getMaximumSize(JComponent)
082: */
083: public void testGetMaximumSize() {
084: assertEquals("== minimumSize (JRockit fails)", ui
085: .getMinimumSize(icon), ui.getMaximumSize(icon));
086: }
087:
088: /*
089: * Class under test for Dimension getMinimumSize(JComponent)
090: */
091: public void testGetMinimumSize() {
092: assertEquals("== preferredSize (JRockit fails)", ui
093: .getPreferredSize(icon), ui.getMinimumSize(icon));
094: }
095:
096: /*
097: * Class under test for Dimension getPreferredSize(JComponent)
098: */
099: public void testGetPreferredSize() {
100: Dimension size = ui.getPreferredSize(icon);
101: int desktopIconWidth = UIManager.getInt("DesktopIcon.width");
102: assertEquals("width ok", desktopIconWidth, size.width);
103: icon.setSize(ui.getPreferredSize(icon));
104: icon.doLayout();
105: if (isHarmony()) {
106: assertEquals("height ok", ui.getIconPane()
107: .getPreferredSize().height, ui.getIconPane()
108: .getSize().height);
109: }
110: }
111:
112: public void testInstallComponents() {
113: int count = icon.getComponentCount();
114: ui.uninstallComponents();
115: assertEquals("uninstalled", count - 2, icon.getComponentCount());
116: ui.installComponents();
117: assertEquals("added 2 component", count, icon
118: .getComponentCount());
119: if (isHarmony()) {
120: assertTrue("added iconPane", icon.isAncestorOf(ui
121: .getIconPane()));
122: }
123: }
124:
125: public void testUninstallComponents() {
126: int count = icon.getComponentCount();
127: if (isHarmony()) {
128: assertTrue("added iconPane", icon.isAncestorOf(ui
129: .getIconPane()));
130: }
131: ui.uninstallComponents();
132: assertEquals("uninstalled", count - 2, icon.getComponentCount());
133: if (isHarmony()) {
134: assertFalse("removed iconPane", icon.isAncestorOf(ui
135: .getIconPane()));
136: }
137: }
138:
139: public void testInstallDefaults() {
140: icon.setBackground(null);
141: icon.setForeground(null);
142: icon.setFont(null);
143: ui.installDefaults();
144: assertTrue("opaque", icon.isOpaque());
145: assertNotNull(icon.getBackground());
146: assertNotNull(icon.getForeground());
147: assertNotNull(icon.getFont());
148: }
149:
150: public void testInstallListeners() {
151: // nothing to test
152: }
153:
154: public void testUninstallListeners() {
155: // nothing to test
156: }
157:
158: public void testMetalDesktopIconUI() {
159: // nothing to test
160: }
161: }
|