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;
021:
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024: import java.beans.PropertyVetoException;
025: import javax.accessibility.AccessibleContext;
026: import javax.accessibility.AccessibleRole;
027: import javax.accessibility.AccessibleValue;
028: import javax.swing.plaf.ComponentUI;
029: import javax.swing.plaf.basic.BasicDesktopIconUI;
030:
031: public class JInternalFrame$JDesktopIconTest extends SwingTestCase {
032: /*
033: * This class is used to test that some property is (or is not) a bound property
034: */
035: private class MyPropertyChangeListener implements
036: PropertyChangeListener {
037: public boolean ok;
038:
039: MyPropertyChangeListener() {
040: ok = false;
041: }
042:
043: public void propertyChange(final PropertyChangeEvent e) {
044: ok = true;
045: }
046: }
047:
048: private JInternalFrame.JDesktopIcon icon;
049:
050: private JInternalFrame frame;
051:
052: public JInternalFrame$JDesktopIconTest(final String name) {
053: super (name);
054: }
055:
056: //public static void main(String[] args) {
057: //}
058: /*
059: * @see TestCase#setUp()
060: */
061: @Override
062: protected void setUp() throws Exception {
063: super .setUp();
064: frame = new JInternalFrame();
065: icon = new JInternalFrame.JDesktopIcon(frame);
066: }
067:
068: /*
069: * @see TestCase#tearDown()
070: */
071: @Override
072: protected void tearDown() throws Exception {
073: super .tearDown();
074: }
075:
076: /*
077: * Class under test for void updateUI()
078: */
079: public void testUpdateUI() {
080: icon.setBounds(0, 0, 0, 0);
081: icon.updateUI();
082: ComponentUI ui1 = frame.getUI();
083: ComponentUI ui2 = UIManager.getUI(frame);
084: // at least names of classes must be the same
085: assertEquals(ui2.getClass().getName(), ui1.getClass().getName());
086: assertTrue("size is set to preferred", icon.getSize().equals(
087: icon.getPreferredSize()));
088: }
089:
090: /*
091: * Class under test for void JDesktopIcon(JInternalFrame)
092: */
093: public void testJDesktopIcon() {
094: frame = new JInternalFrame();
095: icon = new JInternalFrame.JDesktopIcon(frame);
096: assertTrue("frame is set", icon.getInternalFrame() == frame);
097: assertTrue("ui != null", icon.getUI() != null);
098: assertTrue("size is set to preferred", icon.getSize().equals(
099: icon.getPreferredSize()));
100: assertFalse("isVisible", icon.isVisible());
101: }
102:
103: /*
104: * Class under test for
105: * void setUI(DesktopIconUI)
106: * DesktopIconUI getUI()
107: */
108: public void testSetGetUI() {
109: BasicDesktopIconUI ui = new BasicDesktopIconUI();
110: icon.setUI(ui);
111: assertTrue(icon.getUI() == ui);
112: }
113:
114: /*
115: * Class under test for
116: * void setInternalFrame(JInternalFrame)
117: * JInternalFrame getInternalFrame()
118: */
119: public void testSetGetInternalFrame() {
120: MyPropertyChangeListener l = new MyPropertyChangeListener();
121: icon.addPropertyChangeListener(l);
122: // test valid set
123: frame = new JInternalFrame();
124: icon.setInternalFrame(frame);
125: assertTrue(icon.getInternalFrame() == frame);
126: assertFalse("internalFrame is not a bound property", l.ok);
127: // test set to null
128: icon.setInternalFrame(null);
129: assertNull(icon.getInternalFrame());
130: }
131:
132: /*
133: * Class under test for JDesktopPane getDesktopPane()
134: */
135: public void testGetDesktopPane() {
136: assertNull("null by default", icon.getDesktopPane());
137: // test when not iconified
138: JDesktopPane desktop = new JDesktopPane();
139: desktop.add(frame);
140: assertTrue("desktop is set", icon.getDesktopPane() == desktop);
141: // test when iconified
142: try {
143: frame.setIcon(true);
144: } catch (PropertyVetoException e) {
145: assertTrue("no exception", false);
146: }
147: assertTrue("desktop is set", icon.getDesktopPane() == desktop);
148: }
149:
150: /*
151: * Class under test for AccessibleContext getAccessibleContext()
152: */
153: public void testGetAccessibleContext() {
154: AccessibleContext c = icon.getAccessibleContext();
155: assertTrue(
156: "instanceof AccessibleJDesktopIcon",
157: c instanceof JInternalFrame.JDesktopIcon.AccessibleJDesktopIcon);
158: // test getAccessibleRole()
159: assertTrue("AccessibleRole ok",
160: c.getAccessibleRole() == AccessibleRole.DESKTOP_ICON);
161: // test getAccessibleValue()
162: assertTrue("AccessibleValue ok", c.getAccessibleValue() == c);
163: // test setCurrentAccessibleValue(), getCurrentAccessibleValue()
164: AccessibleValue value = c.getAccessibleValue();
165: assertTrue("currentAccessibleValue == 0", value
166: .getCurrentAccessibleValue().intValue() == 0);
167: Integer currentAccessibleValue = new Integer(4);
168: boolean set = value
169: .setCurrentAccessibleValue(currentAccessibleValue);
170: assertTrue("setCurrentAccessibleValue returns true", set);
171: set = value.setCurrentAccessibleValue(new Float(5));
172: assertTrue("setCurrentAccessibleValue returns true", set);
173: assertTrue("currentAccessibleValue == 5", value
174: .getCurrentAccessibleValue().intValue() == 5);
175: assertTrue("the object is not the same", value
176: .getCurrentAccessibleValue() != currentAccessibleValue);
177: set = value.setCurrentAccessibleValue(null);
178: assertFalse("setCurrentAccessibleValue returns false", set);
179: // test getMinimumAccessibleValue()
180: assertTrue(
181: "minimumAccessibleValue ok",
182: value.getMinimumAccessibleValue().intValue() == Integer.MIN_VALUE);
183: // test getMaximumAccessibleValue()
184: assertTrue(
185: "maximumAccessibleValue ok",
186: value.getMaximumAccessibleValue().intValue() == Integer.MAX_VALUE);
187: // test other methods
188: assertNull("AccessibleDescription is ok", c
189: .getAccessibleDescription());
190: assertTrue("AccessibleChildrenCount == 2", c
191: .getAccessibleChildrenCount() == 2);
192: }
193:
194: /*
195: * Class under test for String getUIClassID()
196: */
197: public void testGetUIClassID() {
198: assertTrue("getUIClassID() ok",
199: icon.getUIClassID() == "DesktopIconUI");
200: }
201: }
|