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: package javax.swing.plaf.multi;
019:
020: import java.util.Vector;
021:
022: import javax.swing.JButton;
023: import javax.swing.JLabel;
024: import javax.swing.LookAndFeel;
025: import javax.swing.UIManager;
026: import javax.swing.plaf.ComponentUI;
027:
028: import junit.framework.TestCase;
029:
030: public class MultiLookAndFeelTest extends TestCase {
031:
032: private MultiLookAndFeel mlaf = new MultiLookAndFeel();
033:
034: /*
035: * Test method for
036: * 'javax.swing.plaf.multi.MultiLookAndFeel.isNativeLookAndFeel()'
037: */
038: public void testIsNativeLookAndFeel() {
039: assertFalse(mlaf.isNativeLookAndFeel());
040: }
041:
042: /*
043: * Test method for
044: * 'javax.swing.plaf.multi.MultiLookAndFeel.isSupportedLookAndFeel()'
045: */
046: public void testIsSupportedLookAndFeel() {
047: assertTrue(mlaf.isSupportedLookAndFeel());
048: }
049:
050: /*
051: * Test method for 'javax.swing.plaf.multi.MultiLookAndFeel.getName()'
052: */
053: public void testGetName() {
054: assertEquals(mlaf.getName(), "Multiplexing Look and Feel"); //$NON-NLS-1$
055: }
056:
057: /*
058: * Test method for 'javax.swing.plaf.multi.MultiLookAndFeel.getID()'
059: */
060: public void testGetID() {
061: assertEquals(mlaf.getID(), "Multiplex"); //$NON-NLS-1$
062: }
063:
064: /*
065: * Test method for
066: * 'javax.swing.plaf.multi.MultiLookAndFeel.createUIs(ComponentUI, Vector,
067: * JComponent)'
068: */
069: public void testCreateUIs() {
070:
071: JButton button = new JButton();
072: JLabel label = new JLabel();
073: ComponentUI buttonUI = UIManager.getUI(button);
074: ComponentUI labelUI = UIManager.getUI(label);
075: MultiButtonUI multiButtonUI = new MultiButtonUI();
076: MultiLabelUI multiLabelUI = new MultiLabelUI();
077: LookAndFeel auxLaf = new SyserrLookAndFeel();
078:
079: // without auxiliary look and feels createUIs returns UI fron default
080: // look and feel
081: assertEquals(buttonUI, MultiLookAndFeel.createUIs(
082: multiButtonUI, multiButtonUI.uis, button));
083:
084: UIManager.addAuxiliaryLookAndFeel(auxLaf);
085:
086: // SyserrLookAndFeel contains UI for button so createUIs should return
087: // MultiButtonUI
088: assertEquals(multiButtonUI, MultiLookAndFeel.createUIs(
089: multiButtonUI, multiButtonUI.uis, button));
090: // But SyserrLookAndFeel doesn't contain UI for JLabel so createUIs
091: // should return UI from default laf
092: assertEquals(labelUI, MultiLookAndFeel.createUIs(multiLabelUI,
093: multiLabelUI.uis, label));
094:
095: UIManager.removeAuxiliaryLookAndFeel(auxLaf);
096: }
097:
098: /*
099: * Test method for 'javax.swing.plaf.multi.MultiLookAndFeel.getDefaults()'
100: * Defaults contains references to Multi classes only
101: */
102: public void testGetDefaults() {
103: assertEquals(mlaf.getDefaults().get("ButtonUI"), //$NON-NLS-1$
104: "javax.swing.plaf.multi.MultiButtonUI"); //$NON-NLS-1$
105: assertNull(mlaf.getDefaults().get("Button.background")); //$NON-NLS-1$
106: }
107:
108: /*
109: * Test method for
110: * 'javax.swing.plaf.multi.MultiLookAndFeel.uisToArray(Vector)'
111: */
112: @SuppressWarnings("unchecked")
113: public void testUisToArray() {
114:
115: assertEquals(0, MultiLookAndFeel.uisToArray(null).length);
116: assertNull(MultiLookAndFeel.uisToArray(new Vector()));
117:
118: Vector v = new Vector();
119: ComponentUI content = new SyserrButtonUI();
120: v.add(content);
121: assertSame(content, MultiLookAndFeel.uisToArray(v)[0]);
122:
123: v.add(new Object());
124: try {
125: MultiLookAndFeel.uisToArray(v);
126: fail();
127: } catch (Exception e) {
128: // Correct behavior. The exception isn't described in spec
129: }
130: }
131: }
|