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 Alexander T. Simbirtsev
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.awt.Dimension;
023: import javax.swing.JButton;
024: import javax.swing.JSeparator;
025: import javax.swing.SwingConstants;
026: import javax.swing.SwingTestCase;
027: import javax.swing.UIManager;
028: import javax.swing.plaf.ColorUIResource;
029:
030: public class BasicSeparatorUITest extends SwingTestCase {
031: protected BasicSeparatorUI ui;
032:
033: @Override
034: protected void setUp() throws Exception {
035: super .setUp();
036: ui = new BasicSeparatorUI();
037: }
038:
039: @Override
040: protected void tearDown() throws Exception {
041: ui = null;
042: super .tearDown();
043: }
044:
045: /*
046: * Test method for 'javax.swing.plaf.basic.BasicSeparatorUI.getPreferredSize(JComponent)'
047: */
048: public void testGetSizes() {
049: JSeparator separator1 = new JSeparator(
050: SwingConstants.HORIZONTAL);
051: JSeparator separator2 = new JSeparator(SwingConstants.VERTICAL);
052: assertNull(ui.getMinimumSize(new JButton()));
053: separator1.setUI(ui);
054: assertEquals(new Dimension(0, 2), ui
055: .getPreferredSize(separator1));
056: separator2.setUI(ui);
057: assertEquals(new Dimension(2, 0), ui
058: .getPreferredSize(separator2));
059: assertNull(ui.getMaximumSize(new JButton()));
060: }
061:
062: /*
063: * Test method for 'javax.swing.plaf.basic.BasicSeparatorUI.createUI(JComponent)'
064: */
065: public void testCreateUI() {
066: assertNotNull("created UI is not null", BasicSeparatorUI
067: .createUI(new JButton()));
068: assertTrue(
069: "created UI is of the proper class",
070: BasicSeparatorUI.createUI(null) instanceof BasicSeparatorUI);
071: assertNotSame("created UI is of unique", BasicSeparatorUI
072: .createUI(null), BasicSeparatorUI.createUI(null));
073: }
074:
075: /*
076: * Test method for 'javax.swing.plaf.basic.BasicSeparatorUI.installDefaults(JSeparator)'
077: */
078: public void testInstallUninstallDefaults() {
079: JSeparator separator = new JSeparator();
080: separator.setUI(ui);
081: ui.uninstallDefaults(separator);
082: assertNull(ui.highlight);
083: assertNull(ui.shadow);
084: UIManager.put("Separator.highlight", new ColorUIResource(1, 2,
085: 3));
086: UIManager.put("Separator.shadow", new ColorUIResource(10, 20,
087: 30));
088: UIManager.put("Separator.foreground", new ColorUIResource(11,
089: 22, 33));
090: UIManager.put("Separator.background", new ColorUIResource(22,
091: 33, 44));
092: ui.installDefaults(separator);
093: ui.installUI(separator);
094: assertEquals(new ColorUIResource(22, 33, 44), separator
095: .getBackground());
096: assertEquals(new ColorUIResource(11, 22, 33), separator
097: .getForeground());
098: }
099:
100: /*
101: * Test method for 'javax.swing.plaf.basic.BasicSeparatorUI.installListeners(JSeparator)'
102: */
103: public void testInstallUninstallListeners() {
104: }
105:
106: /**
107: * Auxiliary class for testUninstallDefaults()
108: * */
109: class BasicSeparatorUIForTest extends BasicSeparatorUI {
110: public void uninstallDefaults(JSeparator s) {
111: super .uninstallDefaults(s);
112: }
113: }
114:
115: /**
116: * Regression test for HARMONY-2636
117: * */
118: public void testUninstallDefaults() throws NullPointerException {
119: BasicSeparatorUIForTest localBasicSeparatorUI = new BasicSeparatorUIForTest();
120: localBasicSeparatorUI.uninstallDefaults(null);
121: }
122: }
|